title: How to detect MediaPlayer events of youtube from a service
body: <p>I am developing an application to monitor and get statistics on youtube videos played on the phone. </p>
  
  <p>I need to detect events that occur during playback of video, such as the time when the video begins or ends, or breaks that are produced by emptying the buffer.</p>
  
  <p>For breaks, I solved the problem by analyzing the log to identify messages such as:</p>
  
  <pre><code>WARN/MediaPlayer(661): info/warning (701, 0) (PAUSE)
  
  WARN/MediaPlayer(661): info/warning (702, 0) (RESUME)
  </code></pre>
  
  <p>The problem is that I have not found any message in the log to detect the end of the video. Ideally, you can use a OnCompletionListener to detect this event but I have not been able to get away. I think this type of listener will only work on MediaPlayer objects created in the application itself.</p>
  
  <p>In this case, the MediaPlayer has created another application (youtube) and I have no control over that object.</p>
  
  <p>Does anyone know how to detect these events from an external service to the application that created the MediaPlayer? Can I use a BroadcastReceiver? Which?</p>