Android MediaPlayer

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Syntax

  • void setAudioStreamType(int streamtype)
  • void setDataSource(Context context, Uri uri)
  • void prepare()
  • void prepareAsync()
  • void start()
  • void stop()

Remarks

The MediaPlayer usage is mainly based on the State diagram:

enter image description here

That means that in order to play audio/video a defined sequence of action must occur is specific order. It also states what actions can be made in which state.

The MediaPlayer API lacks flexibility (adding custom decoder and rendering logic) and lacks sSupport for Dynamic Adaptive Streaming over HTTP (DASH) and SmoothStreaming. For these, look into ExoPlayer.



Got any Android Question?