Play playlist with MediaPlayer
I'm trying to play a playlist I get using the MediaStore provider. However, when I try playing a playlist nothing happens. Can a MediaPlayer play a playlist (m3u file) and do I need to set the first track to play ?
This is my test code in the onCreate() method:
Uri uri = MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI;
if(uri == null) {
Log.e("Uri = null");
}
String[] projection = new String[] { MediaStore.Audio.Playlists._ID, MediaStore.Audio.Playlists.NAME, MediaStore.Audio.Playlists.DATA };
Cursor c = managedQuery(uri, projection, null, null, null);
if(c == null) {
Toast.makeText(getApplicationContext(), R.string.alarm_tone_picker_error, Toast.LENGTH_LONG).show();
return;
}
if(!c.moveToFirst()) {
c.close();
Toast.makeText(getApplicationContext(), R.string.alarm_tone_picker_no_music, Toast.LENGTH_LONG).show();
return;
}
c.moveToFirst();
try {
MediaPlayer player = new MediaPlayer();
player.setDataSource(c.getString(2));
player.start();
} catch(Exception e) {
e.printStackTrace();
}
I have turned on every volume stream.
Thanks you,
Kaloer
Asked by: Dainton738 | Posted: 20-01-2022
Answer 1
I don't think media player can play a playlist. I think it will only play a track. You will have to keep track of the tracks from the playlist and pass them to the media player. It might help you to check out the android source code for the music player and how it handles it.
Answered by: Dainton906 | Posted: 21-02-2022Similar questions
android - Java random MediaPlayer playlist
I'm creating an android app on eclipse. When I start my activity I've made it play music (song1.wav)in the background. However how could I change it so that it plays a list of songs in a random order?
Here's my code:
public class BCTR extends Activity {
protected MediaPlayer song1MediaPlayer;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundl...
java - MediaPlayer open M3U Playlist
I tried to create a MediaPlayer.
First I added a local MP3 File on it (over raw directory)
final MediaPlayer mp = MediaPlayer.create(MainActivity.this,R.raw.local_track_1);
mp.start();
Everything worked fine, now i tried to load a M3U Playlist
final MediaPlayer mp = MediaPlayer.create(MainActivity.this,R.raw.playlist1_local_simple);
mp.start();
But now i g...
android - How to clear the current MediaPlayer playlist?
I need to clear current playlist, when a user choose another playlist. When I choose another playlist, method onChildrenLoaded() called and there is some code, but it's problem, because this method add items to current playlist, but not clear it. I think, I need to add method "clearPlaylist()" to my MediaControllerCompat, but this class is declarated as final. How I can solve my problem?
for (mediaI...
Streaming with Android MediaPlayer - catching errors and buffering
I'm having trouble getting MediaPlayer to be resilient when streaming from a HTTP URL.
If I start playing the file, but then drop the connection (e.g. airplane mode), MediaPlayer#OnErrorListener generates what=1, extra=-17 and then shortly afterwards what=-38, extra=0.
There's no documentation I can see in the APIs of what this denotes, except extra is "T...
How to get gapless playback?in android mediaplayer
I am trying to play continuous stream using android mediaplayer.but am not able to avoid gap in playback while updating the datasource file of mediaplayer.Hw can i overcome this problem?
Thanks in advance
media player - Android - Buffering in MediaPlayer
I am using MediaPlayer to play a video in my app. The video takes a while to buffer and the videoview is blank for that time.
Is there a way to start the buffering when the user is in the previous screen, so that when he comes to the video playing screen, the video is ready to play?
Thanks
Chris
android - Problems with MediaPlayer, raw resources, stop and start
I'm new to Android development and I have a question/problem.
I'm playing around with the MediaPlayer class to reproduce some sounds/music. I am playing raw resources (res/raw) and it looks kind of easy.
To play a raw resource, the MediaPlayer has to be initialized like this:
MediaPlayer mp = MediaPlayer.create(appContext, R.raw.song);
mp.start();
Until he...
media player - Android MediaPlayer ignores it's internal volume when the system volume changes
here is my situation:
I have a media player playing music in an Android application. I've found that with certain headphones, the volume is much too loud even when the volume is set to it's lowest setting. As a result, I want to change the volume of the music for all volume levels to be 10% of what it normally is (actually, this value is user-defined of course).
The following works perfectly:
android - Strange behaviour with mediaplayer and seekTo
I'm implementing a custom video player because I need custom video controls. I have an app with only one activity, which on startup shall start playing a video right away.
Now, the problem I have is:
I don't want the video to start from the beginning, but from a later position. Therefore I do a seekTo(16867). Since seekTo is asynchronous, I place the start call of the mediaplayer (player.start()) in the on...
android - Error creating MediaPlayer with Uri or file in assets
I copied song.mp3 to my project's assets directory and wrote this code:
private MediaPlayer mp;
Uri uri = Uri.parse("file:///android_asset/song.mp3");
mp=MediaPlayer.create(this, uri);
After running the create statement, the variable mp is null. What is wrong?
Thanks.
audio - Android MediaPlayer - only one instance at any given time?
I have a audio player app, where there is a Main activity that shows 3 audio sample urls. On click on one, it goes to a Details Activity, which has a play and pause button, to start and pause the audio.
My problem is that, when I start the Main activity, and say click on audio 1, I hit play on Details activity. This starts the MediaPlayer and the audio starts to play. When I go back to the Main activity, the audio...
Getting streaming audio to play with MediaPlayer class on Android?
Hello I am currently new to android development I been working on the examples in the Dev Guide in the android website. I want to get a stream from a server I have to play in the emulator when I insert the url it doesn't seam to want to play. My question is there a way to get the emulator to play audio or is it all enabled also does MediaPlayer require a special kind of format like mp3 or ogg ?
This is the co...
android - Pause any mediaplayer on some event
I have created an application that read messages with voice. I would like to pause any running media player when a message arrives in order to make the voice more clear. Is there any intent that could achieve this aim? I have noticed that google navigator, for example, is able to pause media player (and other music app like pandora).
Thanks in advance
Tobia Loschiavo
Still can't find your answer? Check out these communities...
Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android