Play audio trough phone speaker of an android device - android

Is it possible to play audio trough the phone speaker of an android device?
The smaller speaker inside a phone that produces a low volume sound which can only be heard when listing closely with your ear against the phone.
Hopefully my description is clear enough to understand my question.
If it is possible, a example for how to accomplish this would be really helpful.
EDIT
Currently i'm using the following code to initialize my MediaPlayer.
mediaPlayer = new MediaPlayer();
mediaPlayer.setOnBufferingUpdateListener(this);
mediaPlayer.setOnCompletionListener(this);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);
mediaPlayer.setDataSource(audioPath);
mediaPlayer.prepare();

If you want to play audio through the earpiece, use the STREAM_VOICE_CALL stream type. If you use the MediaPlayer class there's a setAudioStreamType method that you can use for this purpose, and for the AudioTrack class you pass the stream type to the constructor.

Related

Playing the same music file in the same time on speaker and earpiece, Android

Is it possible to do it on android? Ofc I'm talking about phones that use only one speaker for media playback. My phone is Nexus5X. I dont want to root it or mess with system files cause of warranty. So can an app without root be made to do smth like that?
p.s. I tried SoundAbout didnt work.
I think you want to play a music file in phone speaker as well as Head Phone. If Yes means, It's Possible.
// Read the music file from the asset folder
afd = this.getAssets().openFd("background_music.mp3");
// Creation of new media player;
player = new MediaPlayer();
// Set the player music source.
player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
player.setAudioStreamType(AudioManager.STREAM_ALARM);
// Set the looping and play the music.
player.setLooping(true);
player.prepare();
player.start();
Here player.setAudioStreamType(AudioManager.STREAM_ALARM); will act as alarm service, means the audio in the asset folder will play in both headphones and speaker.
Hope it will Help you....

Android media playback - stop audio output completely?

I have an app that plays video files with no audio. I'm using the mediaplayer function. I want to have the videos play, but not output anything to audio, as there is no audio tracks. However, Android ducks all other audio output (music, for example) when my app is running. Is there a way to use mediaplayer and completely remove my app from audio streams?
I've reviewed Google's Managing Audio Focus article, and I can't devise a way to do so. I just want to use mediaplayer for the video, and completely forget about audio.
Is there a different function I have to call in mediaPlayer.setAudioStreamType?
you can mute all the audio streams using the below code snippet
AudioManager am = (AudioManager)NextVideoPlayer.this.getSystemService(Context.AUDIO_SERVICE);
am.setStreamMute(AudioManager.STREAM_MUSIC, true);

How to Control media player android while Playing Rtsp Link on Samsung Galaxy S3?

I have made a small app for playing live stream.It is working good on other devices but on Samsung Galaxy S3 can not control the media player. I am using media player using the following code
sdrPlayer = new MediaPlayer();
sdrPlayer.setOnErrorListener(video.this);
sdrPlayer.setOnCompletionListener(video.this);
sdrPlayer.setOnPreparedListener(video.this);
sdrPlayer.setOnBufferingUpdateListener(video.this);
sdrPlayer.setDataSource(video.this, Uri.parse(url));
sdrPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
sdrPlayer.setScreenOnWhilePlaying(true);
sdrPlayer.prepareAsync();
but media player is throwing the issue media player error (1, -110) but I do not know the meaning of this error and also there is no proper documentation. I found this documentation but I can not get the error and also media player starts playing a bit late after calling start function in on prepare listener.I can not control the pause and play of the stream.
Any kind of help will be highly appreciable.
It is not enough of information. I think adding more code, may be even full file, would help. As per my experience, S3 is less troublesome device on playing rtsp streams, I have created rtsp player too. You might have done something wrong. Let's also ask what the stream you are trying to play, hls, anything else?
You could also do the following:
try to play the stream with some desktop player: quicktime, mplayer.
Do they play it right?
try to validate the stream with one of those rtsp streams validators, do they find it ok?

Difference between Audiomanager and MediaPlayer

Can anybody explain me what's the difference between AudioManager and MediaPlayer in Android ? If I am correct, then AudioManager can only play audio, while MediaPlayer can play both audio and video. But I believe there must be more to this.
Thanks.
AudioManager doesn't play sound at all. It provides access to sound settings, but to play sounds easily, you should use MediaPlayer, SoundPool, or possibly AudioTrack.
From the docs:
AudioManager provides access to volume and ringer mode control.
AudioManager is used to manage audio settings. This includes volume control and the streaming channels (e.g. ringer, media, in-call, etc.).
MediaPlayer is used for controlling the playback (e.g. stop, play, pause, etc.) of audio/video streams.

Android Mediaplayer :: How to detect streaming content type (audio or video)

I am completely new to displaying streaming either audio or video content using media player.
Somehow using post available here, i am able to display RTSP content(.3gp video) in my MediaPlayer implementation.
How to identify streaming content is audio only stream or audio/video stream using MediaPlayer class or streaming link?
I could be wrong here, but I believe there is only a MediaPLayer.OnInfoListner API available in Java to get information about the content stream being played. Not sure of how helpful that API actually is though. You might also want to try stream scrapers(is what I believe they are called) to get stream data and see if there is both audio and video channel to make a determination.

Categories

Resources