Play Wav / Mp3 Output From Tts With Mediacontroller
Solution 1:
You need to pay more attention to the MediaPlayer
's state machine and design your interaction with it more carefully around that. To be specific, you cannot call release
in the completion callback and expect to be able to use the same MediaPlayer
again.
You can instead call reset
in the completion callback and go through the code you have in initializeMediaPlayer
again. Or alternatively, you can try seeking to zero to avoid re-preparing the source (although preparing a local file is negligible in terms of performance).
Edit:
About your MediaController
problem... it can be a bit wonky in the emulator. I have a few suggestions.
1) Basically never use getApplicationContext()
, especially not from inside an Activity
(which already is a Context
). (This probably doesn't help get the controller to show, but is just a general tip.)
2) You are passing R.layout.activity_main
to findViewById
. I don't think that's correct. It should be R.id.___
for the ID of a view defined inside the layout. You can define the IDs with the android:id
tag in the layout XML.
3) I could not get the controller to show when passing the ID of an empty LinearLayout
. If you want to use a layout, you may need to put some kind of view inside it. I put a TextView
inside it and viola, I had a controller. It doesn't show for long, so pay attention. There may be a parameter to set for the display timeout.
Post a Comment for "Play Wav / Mp3 Output From Tts With Mediacontroller"