Questions tagged [android-mediaplayer]

MediaPlayer class can be used to control playback of audio/video files and streams in Android devices

MediaPlayer class can be used to control playback of audio/video files and streams.

4792 questions
183
votes
21 answers

MediaSessionCompat:Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent

I'm trying to update my application to Android SDK 31 but I'm having an issue with MediaSessionCompat. I have a MediaService that extends the MediaBrowserServiceCompat() and in method onCreate of that service I initialise the…
Adelino
  • 2,530
  • 4
  • 20
  • 32
144
votes
13 answers

Play sound on button click android

How do I get a button to play a sound from raw when click? I just created a button with id button1, but whatever code I write, all is wrong. import android.media.MediaPlayer; public class BasicScreenActivity extends Activity { @Override …
Dmitry
  • 1,499
  • 3
  • 12
  • 10
142
votes
6 answers

Play audio file from the assets directory

I have the following code: AssetFileDescriptor afd = getAssets().openFd("AudioFile.mp3"); player = new MediaPlayer(); player.setDataSource(afd.getFileDescriptor()); player.prepare(); player.start(); The problem is that, when I run this code, it…
Catalin Morosan
  • 7,897
  • 11
  • 53
  • 73
138
votes
3 answers

Should have subtitle controller already set Mediaplayer error Android

Whenever I play a media, it shows a warning in DDMS Should have subtitle controller already set MY CODE: private void start() { mediaPlayer.start(); mediaPlayer.setOnCompletionListener(new OnCompletionListener() { @Override …
Sai
  • 15,188
  • 20
  • 81
  • 121
131
votes
17 answers

Media Player called in state 0, error (-38,0)

I am currently trying to design a simple app that streams an internet radio station. I have the URL for the station and am setting up the Media Player like MediaPlayer mediaPlayer = new MediaPlayer(); try { …
SmashCode
  • 4,227
  • 8
  • 38
  • 56
98
votes
4 answers

What is the difference between MediaPlayer and VideoView in Android

I was wondering if there's a difference between them when it comes to streaming videos. I know VideoView can be used for streaming and what is Mediaplayer for? As far as I know, MediaPlayer can do the same thing as VideoView right? Can anyone give…
oattie
  • 1,021
  • 2
  • 8
  • 5
88
votes
7 answers

Streaming Audio from A URL in Android using MediaPlayer?

I've been trying to stream mp3's over http using Android's built in MediaPlayer class. The documentation would suggest to me that this should be as easy as : MediaPlayer mp = new…
Pandalover
  • 2,388
  • 3
  • 21
  • 19
75
votes
5 answers

Media Player Looping : Android

I am having 3 secs of mp3 file. I want to play that mp3 file continuously still the user click pause button. Is there any method to loop the single file and play it again again till user pauses it.
Dray
  • 1,904
  • 5
  • 27
  • 42
68
votes
13 answers

SeekBar and media player in android

I have a simple player and recorder. Everything works great but have one problem. I want to add seek bar to see progress in playing record and use this seek bar to set the place from the player should play. I have onProgress but with no effect. This…
edi233
  • 3,511
  • 13
  • 56
  • 97
61
votes
5 answers

How to fit video in Live wallpaper, by center-crop and by fitting to width/height?

Background I'm making a live wallpaper that can show a video. In the beginning I thought this is going to be very hard, so some people suggested using OpenGL solutions or other, very complex solutions (such as this one). Anyway, for this, I've found…
android developer
  • 114,585
  • 152
  • 739
  • 1,270
53
votes
6 answers

Why does it take so long for Android's MediaPlayer to prepare some live streams for playback?

I am finding big differences in the time it takes the Android MediaPlayer to prepare for live stream playback with different streams. The hard data I added logging between prepareAsync() and the onPrepared(MediaPlayer mp) callback and tested several…
46
votes
6 answers

Mediaplayer error (-19,0) after repeated plays

I have a game in which a sound plays when a level is completed. Everything works fine to start with but after repeating a level 10 or 20 times the logcat suddenly reports: "MediaPlayer error (-19,0)" and/or "MediaPlayer start called in state 0" and…
Mick
  • 8,284
  • 22
  • 81
  • 173
42
votes
5 answers

IllegalStateException for MediaPlayer.prepareAsync

05-19 11:52:51.622: ERROR/MediaPlayer(1291): prepareAsync called in state 8 05-19 11:52:51.622: WARN/System.err(1291): java.lang.IllegalStateException try { mp = MediaPlayer.create( Main.this, …
hunterp
  • 15,716
  • 18
  • 63
  • 115
42
votes
5 answers

Android - play sound on button click - Null pointer exception

I am trying to play a sound file on the click of a button. The sound is just 1 sec long. It plays well the first few times I click the button, but after a while it gives a NullPointerException. Here's the code: button[i].setOnClickListener(new…
Chris
  • 3,787
  • 13
  • 42
  • 49
41
votes
3 answers

Media Session Compat not showing Lockscreen controls on Pre-Lollipop

I'm using MediaSessionCompat from AppCompat Support Library Revision 22. And on Lollipop I'm getting notification & also the background of lockscreen is the album art. And everything works cool. While on Pre-Lollipop devices, the music controls on…
1
2 3
99 100