Getting streaming audio to play with MediaPlayer class on Android? - android

Hello I am currently new to android development I been working on the examples in the Dev Guide in the android website. I want to get a stream from a server I have to play in the emulator when I insert the url it doesn't seam to want to play. My question is there a way to get the emulator to play audio or is it all enabled also does MediaPlayer require a special kind of format like mp3 or ogg ?
This is the code i am running on my 'onCreate()' method.
MediaPlayer mp - new MediaPlayer();
mp.setDataSource(MY_URL_);
mp.prepare();
mp.start();
Hope you guys can help my out.

The code is correct, it works on my device and it doesn't work on emulator. So I guess you need device to hear the sound.

You used to be able to set a flag "-useaudio" in the command build scripts, but now it seems the emulator won't play sound, or at least mine won't.

Related

Problem with playing audio files on ios which is recored on android

I'm using cordova-plugin-media for recording and playing audio files in an ionic project. The problem is when I record a file in android device, in ios device it's not playing but in reverse every sound plays fine. I tried "mp3", "wav" and "aac" format but it doesn't make any difference. can any one help me how to fix it? Thank you
Finally I found the answer. The answer is using "cordova-plugin-media-with-compression" instead of "cordova-plugin-media". Its "startRecordWithCompression" method adds SampleRate to recorded audios which is required in ios.
see the link below:
https://github.com/remoorejr/cordova-plugin-media-with-compression

Android Things video playback on Raspberry Pi

Has anyone been able to successfully play a video using Android Things on a Raspberry Pi? If so was there anything special you had to do to get it to work? If not does any one know why it isn't working?
I made a simple video player that plays a local video from disk. The app runs fine on a phone but I get an error dialog on the Pi saying "Can't play this video".
One Thing I have already ran into but I think I solved was there are no content providers in Android Things, so instead of using a uri for the video source I gave it a file directly like so.
EDIT: Code edit
VideoView videoPanel;
.
.
.
videoPanel.SetVideoURI(Android.Net.Uri.FromFile(new Java.IO.File("/sdcard/Movies/videoFile.mp4")));
I was using 0.5.1-devpreview with raspberry pi 3, and tried to use exoplayer to play mp4. Audio works but not video (just black screen). Same result for youtube iframe sdk (black screen with only audio playing).
I was able to get it to work for my project using setVideoPath instead of SetVideoURI. So your code would be
File file = new Java.IO.File("/sdcard/Movies/videoFile.mp4");
videoPanel.setVideoPath(file.getAbsolutePath());
Try adding this
android:hardwareAccelerated="true"
to your activity in the manifest.

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?

android, recording audio with the emulator

i just new in the android world.
Basically i just want to record the users voice.
I have downloaded some samples and i have not been able to test them using the emulator.
Sine it's possible to enable "audio recording support" when creating a new Android Virtual Device, i'm just guessing what's wrong here.
questions:
is it possible to use the emulator for audio recording? how?
thanks
Media Recorder can be used to record video and audio. However it mentions that currently, MediaRecorder does not work on the emulator. If your samples are using this class, it seems it will not work on the emulator.
Also, it would be a good idea to post links to the samples you mentioned.

Use Android MediaPlayer class to play a video from a URL

Can anyone tell me if the Android MediaPlayer class is able to play a video stored in a remote URL?
Just for testing purposes, can I use the URL http://localhost/video-name.3gp.
Can anyone tell me if the Android
MediaPlayer class is able to play a
video stored in a remoted URL?
Yes, if the video is safe for streaming.
Just for testing purposes, can I use
the URL
http://localhost/video-name.3gp
No. localhost is going to be the emulator itself.
Another question is if the MediaPlayer
works well on the emulator?
Only if you have a fairly fast machine, and not for streaming. You absolutely need hardware to test streaming video.
Ans:- Yes
create a media player object
Mediaplayer ob=mediaplayer.Create(mediaplayerActivity.this,file);
ob.start();
ob.play()

Categories

Resources