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

后端 未结 4 1597
無奈伤痛
無奈伤痛 2020-11-29 05:15

NOTE: I\'m not working at the company where I worked when I posted this question, therefore, even though some great answers might come in, I won\'t act

相关标签:
4条回答
  • 2020-11-29 05:56

    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.

    0 讨论(0)
  • 2020-11-29 06:03

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

    0 讨论(0)
  • 2020-11-29 06:08

    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.
    0 讨论(0)
  • 2020-11-29 06:09

    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/

    0 讨论(0)
提交回复
热议问题