android code for streaming shoutcast stream breaks in 2.2

旧时模样 提交于 2019-11-29 23:18:31

I traced your error a little bit... Looking down in Froyo's source code, in frameworks/base/media/libmedia/mediaplayer.cpp, it comes down to this function. At this point, apparently the player argument is NULL

status_t MediaPlayer::setDataSource(const sp<IMediaPlayer>& player)
{
    status_t err = UNKNOWN_ERROR;
    sp<IMediaPlayer> p;
    { // scope for the lock
        Mutex::Autolock _l(mLock);

        if ( !( (mCurrentState & MEDIA_PLAYER_IDLE) ||
                (mCurrentState == MEDIA_PLAYER_STATE_ERROR ) ) ) {
            LOGE("setDataSource called in state %d", mCurrentState);
            return INVALID_OPERATION;
        }

        clear_l();
        p = mPlayer;
        mPlayer = player;
        if (player != 0) {
            mCurrentState = MEDIA_PLAYER_INITIALIZED;
            err = NO_ERROR;
        } else {
            LOGE("Unable to to create media player");
        }
    }

    if (p != 0) {
        p->disconnect();
    }

    return err;
}

That came from the function status_t MediaPlayer::setDataSource(const char *url, const KeyedVector<String8, String8> *headers) from the same file, where it was able to instantiate the IMediaPlayerService, but the create method must have failed for some reason...

One thing from the Android doc : When done with the MediaPlayer, you should call release(), to free the resources. If not released, too many MediaPlayer instances may result in an exception.

Maybe you should check the createMediaPlayer function is called only once ? I guess that would have failed also with Eclair, but may be worth looking into...

Or maybe what you are looking at is what is described here

Hope that helps

I experienced the same error with my MediaPlayer code. I had various results playing simple test.ogg file located in the raw directory. My AVD's were able to play the file, SE Xperia Mini Pro played the sound, but my Samsung SII crashed using the simple code below.

MediaPlayer mediaPlayer = MediaPlayer.create(this.getBaseContext(), R.raw.test);
mediaPlayer.start();

I received the same error like you

Error initializing the MediaPlayer.
java.io.IOException: setDataSourceFD failed.

I further tested playing the file over the local network with expected results for both phones (SE played the file and Samsung could not play it). This pretty much means that different Android versions are unable to play the same sound and you need to use difference audio format.

If the phone is unable to play the file natively, the only workaround for me is to resample the audio.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!