Android MediaPlayer error -1004 (ERROR_IO) - android

My application plays audio stream
Here the code:
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(url);
mediaPlayer.prepare();
mediaPlayer.start();
url is local file (127.0.0.1)
I use my own HttpServer which runs on the same phone.
After call to
mediaPlayer.prepare();
I get the error:
error (1, -1004) which is ERROR_IO
Any idea what is this error?
Thanks, Costa.

the problem is php5 which sends a 500 http header if your server does not send the correct headers

Android MediaPlayer error -1004 (ERROR_IO)
You can use mediaPlayer.prepareAsync(), but not mediaPlayer.prepare().
Please try it...

The problem was with HTTP server.
I used alternative server:
http://www.prasannatech.net/2008/10/simple-http-server-java.html
And it works great!

I change my video from mp4 to 3gp.
Its work for me.

Related

Android MediaPlayer Won't Stream from HTTP

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.

Mediaplayer is downloading the whole file instead of streaming it - HTTP streaming with flask backend

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

URl not played in android MediaPlayer

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.

live audio streaming in android

I am facing problem to play a audio url using MediaPlayer as well as native Android audio player.
Here is my url
http://live.politiafm.com:8500/politiafm.mp3
Here is my code
Using native audio player
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(STREAM_URL), "audio/*");
StartActivity(intent);
Using Media Player
MediaPlayer mp = new MediaPlayer();
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp.create(Landing.this, Uri.parse(STREAM_URL));
mp.prepareAsync();
mp.start();
In both the cases audio is not playing. Can some body help me out from this trouble.
Thanks & Regards
I guess it is to late a reply but in case if you are still facing the same problem,
you need to enable mime type for your server based on the type of the server. The MIME types are something you can learn from here how to enable them for Tomcat Server, IIS Server or Apache, whichever your mp3 file is hosted on : http://www.developershome.com/wap/wapServerSetup/tutorial.asp?page=settingUpMIME
Thanks
try changing
mp.prepare();
not
mp.prepareAsyunc();

PVMFErrContentInvalidForProgressivePlayback MediaPlayer IOException: Prepare failed.: status=0xC8

I want to play video from a URL via HTTP. I read Media Tutorial and other stackoverflow questions. Here is my code:
String url = "http://..../myVideo.mp4"
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(url);
mediaPlayer.prepare();
mediaPlayer.start();
mediaPlayer.prepare() is throwing IOException: Prepare failed. For the test purpose I record a video using my mobile phone and then I put the mp4 file to server.
I missed this line from stack trace:
08-17 14:36:58.005: ERROR/PlayerDriver(1943): Command PLAYER_INIT completed with an error
or info PVMFErrContentInvalidForProgressivePlayback
The problem is: my video is not capable of progressive download.
The only solution I figured out is using MP4Box which can be downloaded from here.
To make video ready for android I just run MP4Box.exe -hint myVideo.mp4.

Categories

Resources