Question about MediaPlayer and MediaPlayerStream events

frapel

Active Member
Licensed User
Longtime User
Hi,
I'm using MediaPlayer and MediaPlayerStream objects to play local and to stream remote audio files.

MediaPlayer has the Initialize2(EventName As String) method for setting a EventName_Complete called when the audio file reproduction finishes.

In contrast, MediaPlayerStream available events are StreamReady, StreamError and StreamBuffer. There is not a Complete event.

Now, my question is: how may I understand (by code) that audio file reproduction reach its end when I'm using a MediaPlayerStream object ?

Best regards,
Francesco Pellone
 

frapel

Active Member
Licensed User
Longtime User
You can check if the media "IsPlaying", check the documentation for MediaPlayerStream

Thank you for reply. I've already tried your solution (with a running service too) but in some cases it doesn't work. Probably 'cause the MediaPlayerStream starts playing in asynchronous manner, so it would be useful to have a Complete Event as for the MediaPlayer object: I will not test THE END 'cause I will notified of THE END. It's much more simple.

If you look at official Android docs for MediaPlayer you will see a setOnCompletionListener (MediaPlayer.OnCompletionListener listener) method. Since the java MediaPlayer object manages both local audio files and remote audio stream the "Complete" event (or OnCompletionListener) is always available.
MediaPlayer | Android Developers

Maybe we could ask Erel to implement it for Audio library 1.4 version...
 
Last edited:
Upvote 0

frapel

Active Member
Licensed User
Longtime User
If you need to know the status, you need to use a Timer to check if the media is still playing or not.

I tried with a Timer too. Still doesn't work in some circumstances, for example if the timer starts immediately and the MediaPlayerStream is loading (not yet ready to play the remote stream) IsPlaying will report false. But this doesn't mean that stream is completed (really it never started).

Tried too to start the timer at last line of StreamReady event, and again in some case the test fails (the async mechanism is the trouble?)...

To be sure of completion I think the only way is a Complete event, exactly as for the MediaPlayer object.
 
Last edited:
Upvote 0
Top