Media Player Looping : Android
mMediaPlayer.setLooping(true);
mMediaPlayer.setLooping(true);
simple Media Player with streaming example.For xml part you need one button with id button1 and two images in your drawable folder with name button_pause and button_play and please don’t forget to add the internet permission in your manifest. public class MainActivity extends Activity { private Button btn; /** * help to toggle between play … Read more
Was asking the same question and as I understood from what Mark (CommonsWare) advised on numerous threads here, VideoView is a wrapper (200 hundred lines of code) for MediaPlayer and SurfaceView to provide embedded controls. He also kindly shared some examples: https://github.com/commonsguy/cw-advandroid/blob/master/Media/Video/src/com/commonsware/android/video/VideoDemo.java https://github.com/commonsguy/vidtry/blob/master/src/com/commonsware/android/vidtry/Player.java and example from android sdk http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/media/MediaPlayerDemo.html Also some people had issues playing … Read more
You need to call mediaPlayer.start() in the onPrepared method by using a listener. You are getting this error because you are calling mediaPlayer.start() before it has reached the prepared state. Here is how you can do it : mp.setDataSource(url); mp.setOnPreparedListener(this); mp.prepareAsync(); public void onPrepared(MediaPlayer player) { player.start(); }
If you are NOT USING PendingIntent anywhere. The issue might be resolved by adding or updating this dependency // required to avoid crash on Android 12 API 31 implementation ‘androidx.work:work-runtime-ktx:2.7.0’ This fixed my problem.
A developer recently added subtitle support to VideoView. When the MediaPlayer starts playing a music (or other source), it checks if there is a SubtitleController and shows this message if it’s not set. It doesn’t seem to care about if the source you want to play is a music or video. Not sure why he … Read more
player.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength()); Your version would work if you had only one file in the assets directory. The asset directory contents are not actually ‘real files’ on disk. All of them are put together one after another. So, if you do not specify where to start and how many bytes to read, the player will read up … Read more
This is the most important part in the code provided in the original post. Button one = (Button) this.findViewById(R.id.button1); final MediaPlayer mp = MediaPlayer.create(this, R.raw.soho); one.setOnClickListener(new OnClickListener(){ public void onClick(View v) { mp.start(); } }); To explain it step by step: Button one = (Button) this.findViewById(R.id.button1); First is the initialization of the button to be … Read more