How to detect youtube MediaPlayer events from a service

I am developing an application for monitoring and receiving statistics on youtube videos played on the phone.

I need to detect events that occur during video playback, such as the start or end time of a video or breaks that are created by emptying the buffer.

For breaks, I solved the problem by analyzing the log to identify messages like:

WARN/MediaPlayer(661): info/warning (701, 0) (PAUSE) WARN/MediaPlayer(661): info/warning (702, 0) (RESUME) 

The problem is that I did not find any messages in the log to detect the end of the video. Ideally, you can use OnCompletionListener to detect this event, but I could not leave. I think that this type of listener will only work on MediaPlayer objects created in the application itself.

In this case, MediaPlayer created another application (youtube), and I do not control this object.

Does anyone know how to detect these events from an external service into the application that created MediaPlayer? Can I use BroadcastReceiver? What?

+4
source share
1 answer

Deploy OnInfoListener and create a method for it.

0
source

All Articles