Also read: 8 Best Free Android Music Players | 2018 Edition
Sr.No | Method & description |
---|---|
1 | isPlaying() This method just returns true/false indicating the song is playing or not |
2 | seekTo(position) This method takes an integer, and move song to that particular position millisecond |
3 | getCurrentPosition() This method returns the current position of song in milliseconds |
4 | getDuration() This method returns the total time duration of song in milliseconds |
5 | reset() This method resets the media player |
6 | release() This method releases any resource attached with MediaPlayer object |
7 | setVolume(float leftVolume, float rightVolume) This method sets the up down volume for this player |
8 | setDataSource(FileDescriptor fd) This method sets the data source of audio/video file |
9 | selectTrack(int index) This method takes an integer, and select the track from the list on that particular index |
10 | getTrackInfo() This method returns an array of track information |
Steps | Description |
---|---|
1 | You will use Android studio IDE to create an Android application under a package com.example.sairamkrishna.myapplication. |
2 | Modify src/MainActivity.java file to add MediaPlayer code. |
3 | Modify the res/layout/activity_main to add respective XML components |
4 | Create a new folder under MediaPlayer with name as raw and place an mp3 music file in it with name as song.mp3 |
5 | Run the application and choose a running android device and install the application on it and verify the results |
In the below code abcindicates the logo of tutorialspoint.com