What are the differences between MediaPlayer, MediaSessionCompat and RemotePlaybackClient - android

I have been searching for days but I am still not able to understand how exactly these differ in functionality and what role does each of them play in Media Playback? It would be very helpful if someone can explain the difference.

how exactly these differ in functionality
That is akin to asking how a shovel, a hammer, and a piece of rope differ in functionality. While all can be considered tools, they are not really replacements for one another in most use cases.
what role does each of them play in Media Playback?
MediaPlayer plays media on the Android device (audio and video, from local or streaming sources).
RemotePlaybackClient directs some other piece of hardware to play media. The classic example of this is using RemotePlaybackClient to tell a Chromecast to play a video.
While I have not dealt with MediaSession (or MediaSessionCompat), it appears to tie your media playback logic with media controllers that live outside your app, such as a Notification.MediaStyle notification (to control media playback from the Android 5.0+ lockscreen), Android Auto, etc.

Related

Which video player is better for .m3u8 format streaming videos in Android? VideoView or ExoPlayer?

I want to play a .m3u8 streaming video with different audio tracks and different subtitles.
Here I have a question like which video player is better to play the .m3u8 streaming videos, with better performance.
I am Trying to solve this by using Native player, that is VideoView but at the time of working with audio-tracks and sub-Titles, I am facing problem with videoView.Here in the videoView I have to handle every thing through by coding ,there is no support form VideoView.
Can I achieve this with Exo player.
Can any body please suggest a best solution for audio tracks and subtitles support in the video player .
ExoPlayer is an application level media player for Android. It
provides an alternative to Android’s MediaPlayer API for playing audio
and video both locally and over the Internet. ExoPlayer supports
features not currently supported by Android’s MediaPlayer API,
including DASH and SmoothStreaming adaptive playbacks. Unlike the
MediaPlayer API, ExoPlayer is easy to customize and extend, and can be
updated through Play Store application updates.
From the documentation.
Exoplayer is super easy to use and it supports SmoothStreaming, in case your link provides multiple tracks, it'll adapt to the user connection, if the user has a poor connection it'll select the lower quality track, if the user has a good internet it'll select the high-quality track.
If playing audio or video is an important feature of your app, you should definetly use Exoplayer.
If you are not convinced yet, Exoplayer is used in Youtube, Google Music, Google Movies, Facebook, Whatsapp, Spotify, Twitter and 140,000 more. You can check in this I/O lecture.
If you want to check a simple audio exoplayer sample you can see it here. And read this article.
as someone who has coped with same problem i think simplicity is more important than other factors. VideoView is so easy to use so go with it.
tip: if you wanna make something like youtube style of playing you can use a Frame Layout on top of that and put buttons and imageviews and other stuff like that on it

Android Service to detect video playback on a third party Video Player

I need to develop an Android Service (API level > 21), which should be able to detect video playback on a third party Video player, so that it can further disable the Notification pop-ups during a video playback.
On searching, I found several posts talking about detecting the play-states of videos in a VideoView, such as the following:
How to detect when VideoView starts playing (Android)?
But, I couldn't find anything that can help detecting video playback on a video player, wherein, the video player is installed as a third party app and is not a part of the Android application/ service.
So, the challenges are:
1) The android service needs to detect a video playback
2) Registering package names for video player apps with the Service is out of question, since the Service should be able to detect the playback even when a new video player is installed from the Playstore.
3) Need to extend this idea for online video streaming as well.
Any help in this regard would be really appreciated.
Thanks in advance.
There is no way to implement 100% reliable video playback detection :(
Just and idea: try listening to the audio focus changes... this might help with detection of video playback, assuming the target player respects the audio output stream usage policy, recommended by Google. You might also want to get notified about system UI visibility changes (to detect fullscreen playback).
Audio focus:
https://developer.android.com/guide/topics/media-apps/volume-and-earphones.html
System UI visibility changes:
https://developer.android.com/reference/android/view/View.OnSystemUiVisibilityChangeListener.html
Also, you are correct saying that package name based detector is not an option since detecting active/running package is no longer possible on android 7.

How to pause/stop video in Android from my application

In Android how can i pause video player from my application.
I am able to achieve this for music player but not for video.
(Note: my application is different from video player. Video is not running in my application. )
In Android how can i pause video player from my application
Contact the authors of the video player you want to control, and ask them if they have an API to allow third-party apps to control their video player.
In general, apps cannot control other apps this way.
I am able to achieve this for music player
It is possible that there is some music player that has a documented and supported API that you are using. Or, perhaps you are attacking some music player with security issues. Many Android developers are capable of creating a music player that cannot be controlled by third-party apps, so please do not assume that whatever you did will work across all music players.

Google Chromecast receiver doesn't play simultaneous audio

I'm developing a Chromecast application (receiver, HTML5 and Javascript) which communicates with an Android app, all is fine, but I have a problem trying to play two "sounds" at a time in the receiver.
It's a kind of game where I need to play a song at the beggining and play some sound effects during it.
Is this possible? And if it is anyone could help me to do it? I have tried it and it works nice in the browser but in the Chromecast only one of the "sound" is played, the song or the effect, never both.
Thank you very much
You cannot have more than one active Media Element in your DOM in chromecast. For what you want to do, however, you can use Web Audio APIs and accomplish the same for short audio files.

Set the volume control stream from a service on Android

I'm working on a music app which consists in a Service playing music while other apps are running.
In order to enjoy the music and only the music, the Service mutes all the other apps. In order to do that, it mutes STREAM_MUSIC and play music over STREAM_VOICE_CALL (found that solution to mute other apps here)
As the Service uses STREAM_VOICE_CALL to play music, what I'm trying to find is a way to make the volume buttons control this stream when a sound is playing.
What I already tried:
setVolumeControlStream: only works in Activities
Capturing volume keys pressed events: Services do not receive such events (source)
audioManager.setMode(AudioManager.MODE_IN_CALL) : does not work in my case. Plus, the SDK documentation states that this "mode should only be used by the telephony application when it places a phone call".
At this point, I'm out of options and any help would be appreciated. Thanks!
I would personally not suggest you to STREAM_VOICE_CALL as it is meant to be recommended to use it for Voice calls as compared to media playback. Using this may prevent you from using features exposed by Android for media playback.
Having said this & taking into consideration your use-case, I think you need to look for changing 'call volume' level as compared to 'media volume' level.
Have a look at the MediaPlaybackService.java as used in the stock Music Player app and try to customize it as per your needs.
I havn't tried it myself. but looks like it should work. Kindly try it out.
m_audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
m_audioManager.setMode(AudioManager.MODE_IN_CALL);

Categories

Resources