I have created an application that read messages with voice. I would like to pause any running media player when a message arrives in order to make the voice more clear. Is there any intent that could achieve this aim? I have noticed that google navigator, for example, is able to pause media player (and other music app like pandora).
Thanks in advance
Tobia Loschiavo
This is not an intent, but have you tried AudioManager and requestAudioFocus?
Sadly its only from API 8
Related
I have an application which uses exoplayer to play videos.
When the user is on player page and presses the power button to close the screen I want the audio to keep playing in the background and notification should be visible to user with controls of play, pause , video metadata etc similar to what we have for every music playing app.
I can keep the audio of video playing from exoplayer using setPlayWhenReady(true).
But I am stuck in for notification. Should I be using MediaBrowserServiceCompat or I will have to create custom notification to handle it?
I think what you should do is to create ForegroundService and create notification as you mentioned to have the ForegroundService working. I think this post might help you:
https://androidwave.com/foreground-service-android-example/
Use a foreground service to implement something like this.This can help you
I've developed a music player app where i need to pause music when user gets a call through his skype app. I've tried AudioFocus and phone state listener concepts but it is not working for skype. Can somebody help me out on this.
Thanks in advance.
This link show you how it done with phone call. Sometimes it will help you.
Stopping & Starting music on incoming calls
I have created a media player application using Android MediaPlayer API. The app is working fine unless a phone call is received. I am handling phone call events in my app and doing pause and play of media player.
The problem is that After pause and play, when phone call arrives, the song is playing but with no sound from speakers.
One more thing is This is happening when I am using bluetooth headset only.
If anybody faced this problem, please reply suggestions to my question.
I solved this problem by stopping bluetooth's SCO before playing a music track if it is ON.
I want to write an application that monitors a music player. In my app I want to start a service, that listens to some media player (best case: any media player; worst case: a specific media player), to get the 10 most listened audio tracks' titles and authors. Is this possible? I searched the web for hours, but I found nothing relevant.
Thanks in advance.
Is this possible?
Not really. There might be some music players that broadcast this information that you could track, but I do not know of any, and that'd be a privacy issue if they did.
My application makes a short announcement once in a while, either via TextToSpeech or using the MediaPlayer. If there is some other music running in the background probably by some application using the MediaPlayer, I would like to interrupt this music for a moment and after my announcement resume playing the "background music".
Is there a way to do it?
If you can target API level 8 and above (Android 2.2), then have a look into the AudioManager, specifically requestAudioFocus() with AUDIOFOCUS_GAIN_TRANSIENT and AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK, and abandonAudioFocus().
These give hints to the currently-playing music stream that your app would like to play a brief sound. If you use AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK with requestAudioFocus() you can get a nice effect where the already-playing music pauses, your sound plays, and then the playing music fades back in again when you call abandonAudioFocus().
This works nicely with the built-in media players on the 2.2 devices I've tried it with (Samsung Galaxy S Wi-Fi and HTC Wildfire.) I've not tried it extensively with other music-playing apps, but it definitely works with Spotify, at least, and is the official way of doing exactly what you want to do.
Note that you'll need to work out for yourself when to call abandonAudioFocus() as most sounds are played asynchronously. Luckily, both MediaPlayer and TextToSpeech provide callback mechanisms so they can give you a prod when they've finished playing your sound (this isn't true of SoundPool, so that's more annoying to use audio focus with.)
I don't think there is a standard way to do it for every music player out there. At least for the Android music player you could do:
Intent i;
i = new Intent("com.android.music.musicservicecommand");
i.putExtra("command", "pause");
context.sendBroadcast(i);
Another way to do it would be to set the stream volume for type "music" to 0, and play your announcement on another stream type.