I have a URL that returns a 8-bit PCM, mono, 8 kHz WAV sound. When I try to play that URL via Android's MediaPlayer class, I get an error and the following in LogCat:
09-29 17:36:40.710: ERROR/PlayerDriver(562): Command PLAYER_INIT completed with an error or info PVMFFailure
09-29 17:36:40.730: ERROR/MediaPlayer(25215): error (1, -1)
The content type that the URL returns is audio/x-wav. I The error occurs after calling prepareAsync():
String uri = "http://whatever";
s_Player.setDataSource(uri);
s_Player.setAudioStreamType(AudioManager.STREAM_MUSIC);
s_Player.prepareAsync();
When I replace uri with a file path to the same sound stored in the filesystem, it plays fine. Playing the URL in the Android browser works. So it must be me somehow misusing MediaPlayer. Any ideas, please?
EDIT: it's on the emulator (for now), so permissions are not an issue.
Maybe you didn't request Internet permission in the manifest???
Related
When setting a MediaPlayer DataSource to a HTTP URL as opposed to an HTTPS URL, no audio streams and MediaPlayer error code -38 is displayed in logs.
I attempted to connect to the stream using ExoPlayer instead, and received this error. Following the docs suggestion, I added the following line of code to the application tag of my application's manifest file:
android:usesCleartextTraffic="true"
I am now able to connect to the stream at HTTP URL using both ExoPlayer and MEdiaPlayer.
I am trying to make an android app that would stream audio from a webserver using http, streaming itself works with VLC and HTML "audio" tag but when trying to stream it using MediaPlayer the file just gets downloaded as a whole, not streamed.
When streamed through VLC/HTML, http response codes are 206(partial data), streaming through MediaPlayer returns 200 every time. File served on the server is in wav format(also tried m4a and mp4)
Code taking care of streaming(basically taken straight from the docs):
String url = "http://localhost:5000/song";
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioAttributes(
new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
.setUsage(AudioAttributes.USAGE_MEDIA)
.build()
);
mediaPlayer.setDataSource(url);
mediaPlayer.prepare();
mediaPlayer.start();
In your first line, change localhost to the ip address where flask is running
String url = "http://192.168.***.***:5000/song";
And run flask with the host as unspecified address (i.e. 0.0.0.0)
app.run(debug=True, host="0.0.0.0", port=5000)
Not sure why this worked, i was just messing around with different host names
Some other tips for people googling this:
Add Internet permission <uses-permission android:name="android.permission.INTERNET" /> in manifest
OP is using a route "/song" which is better solution esp if files are in folder other than static. If your files are in the static folder, you don't need a route and can reference their url directly
String url = "http://192.168.***.***:5000/static/mysong.mp3
I'm creating an input stream to buffer and stream a mp3 from cloud .
URL url = new URL("http://xxxx.yyy.com/Demo.mp3");
InputStream inputStream = url.openStream();
Now how do i playback the mp3 from media player without using a temporary file to store it and read back from the same ? I'm developing for Android Lollipop
I'm pretty sure the MediaPlayer can handle remote URLs. Take a look at this example. Check the setDataSource method from the MediaPlayer class as well.
EDIT: Since you really really want to use an inputstream, I think you'll need to go low-level. Check the AudioTrack class. This SO answer might help. There are also a couple of issues here and here that might be relevant.
This problem persists even today !!! Check these link out https://code.google.com/p/android/issues/detail?id=29870 and
http://www.piterwilson.com/blog/2014/03/11/android-mediaplayer-not-quite-there-yet/ .
There is absolutely no way either to get access and control over the MediaPlayer buffer , neither to feed the buffered mp3 content stored in an byte array into MediaPplayer as an argument to play it . So People either convert the mp3 buffer to PCM and use AudioTrack to play it or write the byte array of the input stream into a local socket and make Mediaplayer read back using the socket file descriptor like mentioned this following link Audio stream buffering
The solution I'm using to feed binary data directly to MediaPlayer is to use ParcelFileDescriptor#createPipe() (API level 9) and MediaPlayer#setDataSource(java.io.FileDescriptor).
Here's sample code (untested):
ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe();
FileDescriptor fd = pipe[0].getFileDescriptor();
mediaPlayer.setDataSource(fd);
OutputStream out = new ParcelFileDescriptor.AutoCloseOutputStream(pipe[1]);
From this point on, whatever you write in the output stream will be received by the MediaPlayer. This is pretty fast since it uses a kernel FIFO to transfer data (no sockets, no TCP) and as far as I understand is fully in RAM (no actual files are used).
I'm working media palyer app, in this i need to stream audio from URL. In my case some URL's are not streamed in some devices (Eg. Samsung Note III), after a long time i got this error message in onError() method.
E/MediaPlayer(24445): error (1, -1004)
I used the following code to pay url.
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(songPreViewUrl);
mediaPlayer.setOnPreparedListener(BackgroundAudioService.this);
mediaPlayer.setOnCompletionListener(BackgroundAudioService.this);
mediaPlayer.setOnBufferingUpdateListener(BackgroundAudioService.this);
mediaPlayer.prepareAsync();
Can any one please share the suggestion, why the urls are not streams in Samsung devices.
My new surveillance camera just arrived, so I'm trying to write an app to live stream the video from it.
Since it came with basically no documentation, I installed the 'onvifer' android app which allows you to browse the camera's capabilities. This app works fine - gets the video and allows PTZ controls, etc. It reports the streaming url as:
rtsp://192.1.0.193:554/mpeg4
I tested the stream in the VLC windows client, and it's able to stream video from that URL as well. This makes me comfortable that the network is working OK.
The camera states the feed will be 1920x1080; VLC confirms this.
The basic code in my activity:
VideoView videoView = (VideoView)this.findViewById(R.id.VideoView);
videoView.setVideoURI(Uri.parse("rtsp://192.1.0.193:554/mpeg4"));
videoView.requestFocus();
videoView.start();
I've also given the app INTERNET permissions in AndroidManifest.xml, disabled authentication on the camera, and am running on a real device (not the emulator).
When I run the app, LogCat shows this immediately:
setDataSource IOException happend :
java.io.FileNotFoundException: No content provider: rtsp://192.1.0.193:554/mpeg4
at android.content.ContentResolver.openTypedAssetFileDescriptor (ContentResolver.java).
About 15 seconds later, the app shows a "Can't play this video" modal dialog box and this is added to LogCat:
MediaPlayer error (100, 0)
AudioSystem AudioFlinger server died!
MediaPlayer error (100, 0)
VideoView Error: 100,0
I've googled everything I can think of, but haven't found anything useful.
Any thoughts?
wild-ass-guess on your logcat and the RC=100... No SDP file or no equivalent for RTSP of the 'moov atom' block required to negotiate details of the stream /container/ codec/ format... You can get the AOSP code for mediaPlayer/videoView and grep the RC value in the source.
RTSP is gnarly to debug ( note the tools links ) and not assured to run inside a NAT'd network due to UDP issues. So, to get better result, you may have to look into forcing your config to do data channel on TCP an not UDP. Or it could be other issues , of which there are many.
If you really want to investigate, some possible tools below:
Use command line and CURL client to request your stream:
Android - Java RTSP Session Mgmt package on Git
Protocol dumps for CLI RTSP sessions to Youtube RTSP/SDP streams
To pursue the issue, you may need to get into the weeds with debug tools that track details of the protocol negotiation that preceeds the MediaPlayer actually starting play on the stream. That would include learning the RFP and the protocol details.
videoView.setVideoURI(“rtsp://192.1.0.193:554/mpeg4”);
Try your app on another phone.
You may find the problem is about the mobile device.
Try this
path:"rtsp://218.204.223.237:554/mobile/1/4C024DFE77DC717D/onnuvesj43xj7t26.sdp".
See whether the code has something wrong.