Reputation: 375
I am working on a remote control for integration between Android TV devices and Smartthings Hub. I want to be able to check if any media app is playing anything on the device (Android TV). If for example, Youtube or Plex app is playing any movie, then I will show the user "playing" , if no app is playing anything , I will display "stopped"
if any type of media (audio or video) is playing, I have to understand this.
I wanted to engage Android mediaplayer with following code, but it did not work:
final MediaPlayer player = new MediaPlayer();
if(player.isPlaying()) {
response.send("playing");
}
else {
response.send("stopped");
}
I am not sure if this instance will attach to the active media player and I couldn't find the correct way. What am I missing ?
Upvotes: 5
Views: 3535
Reputation: 6073
you should use AudioManager
for sound , check the documentation
AudioManager.isMusicActive();
and for video , The SurfaceFlinger process can know that it is receiving frames at a consistent rate, but it can't know if it's a video or just app animation.
The mediaserver process is responsible for managing the hardware video decoders. It can know if a video is being decoded, but it can't know if the video is being displayed. It won't be involved if the app is using a custom software-only decoder.
There isn't an unequivocal way to detect that a video is being played and presented on the display.
Upvotes: 2