Convenience method to create a MediaPlayer for a given Uri. On success, prepare() will already have been called and must not be called again.
The prepare() method will called automatically, so you can't call prepareAsync.
So, you can read this, use MediaPlayer mediaPlayer = new MediaPlayer(); and SetDataSource, and then you can use prepareAsync. If you use prepareAsync you need use setOnPreparedListener method to listener to the onPrepared event.
Answers
Hi @ispirLee25 ,
Form official document, the create method:
The
prepare()
method will called automatically, so you can't call prepareAsync.So, you can read this, use
MediaPlayer mediaPlayer = new MediaPlayer();
andSetDataSource
, and then you can useprepareAsync
. If you useprepareAsync
you need usesetOnPreparedListener
method to listener to theonPrepared
event.Please refer to this case.
Another option in addition to the one supplied by robbit is to create your own async method
then call it:
you will have to add the
async
keyword to the method that the above two lines of code are in so you can useawait
.