How to pause/stop video in Android from my application - android

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.

Related

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.

What are the differences between MediaPlayer, MediaSessionCompat and RemotePlaybackClient

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.

Android - Force VideoView to Intent.action_view [embeded videos via external player]

I have a few app to watch live streams and video clips.
The applications use embeded android video player.
After a search, i recongnized that these apps using VideoView class.
But i want to choice an external player to watch videos which triggered from this apps. (like MX Player or GP Player.)
I think i have to override the videoview class in android. Is this possible?
Or are there any other way to implement this?
Thanks.
May be i can override the Android source files. Is this possible?
No.
Moreover, it would not necessarily work, as there is no requirement that the video be available for viewing in a third-party app. Just because an app can play a video itself does not mean that the same video is accessible by other apps.

How can I auto-pause the audio player in my app when another app starts to play audio?

My app plays an audio file. I want my app to pause the audio playing if another apps starts to play audio. I don't want the two audio sounds mess up each other. My app will resume the audio playing after the other app finishes playing its audio. How can I make it? Thanks.
Depending on how your application is running ie. while app is running in foreground (users is looking at your screen) or if your running a "service" which is currently in the background and you wish music to continue playing (songza, slacker radio etc.) how you handle these things will be different. Android uses internal system states to determine which apps should be out-putting audio to the speaker. All this is handled by the audio manager requestAudioFocus() releaseAudioFocus() will be the system calls you will want to look at the most. For a more detailed explanation see android developer api where you this is explained and documented quite well http://developer.android.com/guide/topics/media/mediaplayer.html

Android: when implementing a music player in my app, can i make sure there is no other media playing playing music right now?

I want my app to play music while it is running, but I don't want the music to overlap with the music currently being played from a different application (android music app or other external music app such as pandora, grooveshark or winamp).
My question is: is there a way to make sure that nothing else is playing right now regardless of the source?
Thanks!
As of android 2.2 you can use AudioManager.requestAudioFocus(), other audio players should listen for this focus change request and can stop/pause/lower volume of their audio according to what type of audio your focus requests. However not all audio playing apps have bothered to implement this yet.
To be nice you should also listen for audio focus change requests from other apps and pause your apps audio accordingly.
On earlier versions of android calling mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); will usually stop any other music from playing

Categories

Resources