MediaPlayer error (1, -1004) aka MEDIA_ERROR_IO trying to stream music on Samsung S3

若如初见. 提交于 2019-11-27 03:59:48

The answer to this question turned out to be an issue on Android firmware installed on Samsung S III devices running Android 4.1.2.

It seemed to have been something relating to the source of the stream, because some sources eventually played on the device, but the one we needed, never played.

If you can get your stream from another source, it should work.

So if you're developing an application for a specific company/purpose and have some control over the source of the stream, or can communicate with people in control of the source of the stream, get them to change the source of the stream to something that'll work on a Samsung S III running Android 4.1.2.

Other than that all that will solve this is a firmware upgrade.

Juan Carlos Ospina Gonzalez

For everyone struggling with this problem here's the solution:

Android MediaPlayer takes long time to prepare and buffer

EDIT : The previous solution is not very complete because it is possible sometimes to hear the player 'stutter' when it pauses and resumes.

A 100% java answer that is slightly more elegant involves using a MediaCodec instance to turn the mp3 into PCM data to feed to an AudioTrack instance.

I have posted full source code and explanation here : http://www.piterwilson.com/blog/2014/03/15/mediacodec-mediaextractor-and-audiotrack-to-the-rescue/

I resolved this issue by using library
compile 'com.devbrackets.android:exomedia:3.0.1'

A definite solution for some getting -1004 on older Samsung phones:

In my case, I'm using a Samsung Galaxy Pocket and had a mp3 file on our CDN, which wouldn't play, i.e.

http://domain/path/audiofile

When downloading the file to the phone, however, it plays in the native player. Not in my app and not in browsers, though. Turns out, the media player service needed a file extension to hint the media type and couldn't auto-detect based on file headers.

I solved it by giving the file location an actual extension.

http://domain/path/audiofile.mp3

Solution

  1. Either give the file an extension where it's hosted (as above) or
  2. Programmatically, download the file manually, give it the correct extension on the sdcard and then play from sdcard as the source.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!