Android media player not producing sound even playing - android

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.

Related

How to check if external media player is playing in android?

I want to stop my media player if external media player is playing.
I've implemented following code but it is called even when my app media player is playing.
if (audioManager.isMusicActive()) {
return;
}
How to distinguish between in-app media player and external media player?
Any help would be appreciated.
Two or more Android apps can play audio to the same output stream
simultaneously. The system mixes everything together. While this is
technically impressive, it can be very aggravating to a user. To avoid
every music app playing at the same time, Android introduces the idea
of audio focus. Only one app can hold audio focus at a time.
Further,
A well-behaved audio app should manage audio focus according to these
general guidelines:
Call requestAudioFocus() immediately before starting to play and
verify that the call returns AUDIOFOCUS_REQUEST_GRANTED. If you design
your app as we describe in this guide, the call to requestAudioFocus()
should be made in the onPlay() callback of your media session. When
another app gains audio focus, stop or pause playing, or duck the
volume down. When playback stops, abandon audio focus. Audio focus is
handled differently depending on the the version of Android that is
running:
You can check the more detail from developer link.

How to play sound in ear speaker in xamarin android?

I'm doing a cross platform app in visual studio, I want to know how to play sound in ear speaker, like mobile ringing sound while we make a call, can any one help me for this?
UPDATE
Actually I was trying to do SIP calling. I have used Android.Net.Sip. I can able to call to SIP Numbers but before pick the call from end user the ring sound cant be ringing in my mobile.
Its having this functions but I cant able hear ring sound
//Called when a RINGING response is received for the INVITE request sent.
public override void OnRingingBack(SipAudioCall call)
{
base.OnRingingBack(call);
}
for this I was tried to play ring sound using media player, but this will use loud speaker, for this I want to play ring sound in ear speaker or can we can able play ring sound using above functions. can any one help me for this?
No need to restart your phone. Just close the running apps and try the audio. It'll be normal, through your main speaker. I've observed one thing. While the music is coming through ear speaker just make a call, that automatically pauses the playing audio, and in the call put on the loud speaker and now go to the music player (don't disconnect the call, let it go in speaker mode) and turn on the music, now the audio will get out through main speaker in normal way. Again putting off the speaker mode of the current going call throw back the audio to ear speaker. After disconnecting that call also the audio will play through ear speaker only. I don't know the reason behind this. This is just my observation. Finally I would like to conclude that, no need to restart your phone. Just close the running apps (all) and now try the audio. It'll be fine.

Pause/Stop/Mute music at service interupts

I basically have an audio application that will be playing some music. I want to be able to pause/stop/mute the music when there is an interrupt.
These interrupts include: GPS directions, Phone Call, GPS, etc. (if there are more audio interupts, please let me know)
I already implemented the phone call interrupt, stops the music when phone call received and plays after phone call ends.
How would I do the other interrupts?
EDIT:
I noticed that Android's Play Music application does this. But I am unable to find the source code of that, not sure if that would be helpful.
Make sure you correctly ask for and release Audio Focus as described here:
http://developer.android.com/training/managing-audio/audio-focus.html
With multiple apps potentially playing audio it's important to think about how they should interact. To avoid every music app playing at the same time, Android uses audio focus to moderate audio playback—only apps that hold the audio focus should play audio.
Basically this allows the framework to handle interrupts properly as you cannot specifically code for every situation.

Stop ringtone and audio in Android when listening audio

I am building an Android app for webradio.
I am using vitamio player that extends the functions of the standard MediaPlayer. This problem could also be happening in the standard Media Player as well.
If I'm listening radio and I receive a call, ringtone starts, but the radio doesn't stop!!!
How can I stop it ?
Which event?
Otherwise, I think what you are looking for if you are a developer of the said app is provided at this link. It provides an example of hooks that monitor phone state. On the ringing or call active states you can set your app to a paused or silent state.

Android media player(android.media.MediaPlayer) two music concurrently

Before open my application I played some of the music from default music player. With that background music I opened my application with the mediaplayer (android.media.MediaPlayer) to play the mp3 available in assets.
The default doesn't stop the music and I am getting two music concurrently from the device.
How do I stop or pause music of the default music player whenever my app started playing the music?
I think thats impossible. The default music player is a different app and out of your control. android does not allow controlling other app features from your app.
I had the same problem. I was trying to stop the background music of the default music player (if it is playing) when my VoIP SIP application receives an incoming call. I came up with:
AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
am.setStreamMute(AudioManager.STREAM_MUSIC, true);
This does not stop or pause the music, but it make the music stream silent. Do not forget to unmute it later. This solution works well only if your second sound does not use the same stream.

Categories

Resources