Can anyone help me to know how to stop the background music playing on android once I open my application in Android (I'm using Appcelerator Titanium)
Titanium Mobile doesn't integrate Android's Audio Focus functionality, as indicated by the lack of Audio Focus-related method calls. Therefore, you aren't able to request permanent audio focus using the framework itself, which would stop audio playback from other active apps.
You can create a Titanium Module that implements this functionality though.
You may have some modest success creating intents for specific applications, for example, sending a pause intent to com.android.music.musicservicecommand, the default music player. See these resources:
android - how to play or resume music of another music player from my code? - Stack Overflow
Android Audio Focus How to » Community Questions & Answers » Appcelerator Developer Center
Related
Is there a flutter solution to securing music app from screen recorder (Even the app runs in the background), like apple music app did, stop the music when you start screen recorder. We have tried windowmanager package & secure application but no one works in IOS.
We have a mobile app to stream music, the app implement in-app purchase, every song should be bought before listening, and the content is exclusive for the app. that's why we need to secure the app, we have searched a lot for flutter packages and native implementations but we haven’t find a solution for IOS specific .
You should implement this natively for iOS.
Use isCaptured property in UIScreen to know if screen recording is happening (you can do this for iOS 11+)
You can use Key-Value Observing to know when isCaptured changes
Apple says:
To prevent the system from recording the audio portion, observe the isCaptured property and take appropriate action in your app as described...
see the documentation
EDIT:
I've found this library flutter_forbidshot it is helpful, and I think it is suitable for this problem.
I am facing the issue, that my App Blocks Background Music when using a MediaElement for Video usage.
The bottom line is that I want to play a silent video and the user should still be able to listen to spotify and etc. in the background
In iOS the procedure to allow Background Music is pretty straight forward. On Android I cannot manage to get it working.
I already tried different xamarin.forms libraries where i set the video to mute or the volume to zero.
But nothing seemed to work. I tried for example octane, mediamanager and several other videoplayers.
For this reason, I would now like to try to implement it in the native Android code.
But I haven't found anything about it in various forums.
Xamarin Forms Version is 4.8
You could use a service to stream audio to play audio while your application is not visible or under the lock screen.
You could check the blog about this and download the source file from the Github. https://devblogs.microsoft.com/xamarin/background-audio-streaming-with-xamarin-android/
I test with the sample in the thread i done before to play the audio. libVLCsharp.forms can not play Android resource video file while iOS can
When i make the app which play music in the background, the music would play as well.
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.
I've created a cordova android application that stream video content from a ustream channel, and its working fine, I now want the app to keep playing the stream when its on a background. At the moment the video stream stops about 2 or 3 seconds after the app goes to background.
Is there a plugin that I can use to achieve that ? I believe this issue is not specific to ustream channels.
Thanks
Android platform has a right to passivate or terminate an application when it's no longer visible. If you need to perform actions when the application is not visible, you have to implement and register a service to do it. More information about Android services can be read here: http://developer.android.com/guide/components/services.html
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