0

我需要为两个视频音频播放 android rtsp 流。但无论我做什么,他们都不会开始。视频的 rstp 流采用 .mp4 格式,音频采用 .mp3 格式。该流在 VLC 中播放时工作正常,它显示的分辨率为 320X240。但在这里它只是给出了我在底部发布的错误。另外请告诉如何流式传输 mp3,因为 android-sdk 的 API Demos 中没有教程。该视频适用于 Vitamio 库。但我不知道如何自定义它。

mMediaPlayer = new MediaPlayer();
        mMediaPlayer.setDataSource(path);
        mMediaPlayer.setDisplay(holder);
        mMediaPlayer.prepare();
        mMediaPlayer.setOnBufferingUpdateListener(this);
        mMediaPlayer.setOnCompletionListener(this);
        mMediaPlayer.setOnPreparedListener(this);
        mMediaPlayer.setOnVideoSizeChangedListener(this);
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

//onPrepared(...) Function
public void onPrepared(MediaPlayer mediaplayer) {
    Log.d(TAG, "onPrepared called");
    mIsVideoReadyToBePlayed = true;
    if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown) {
        startVideoPlayback();
    }
} 

//startVideoPlayback() Function 
    private void startVideoPlayback() {
    Log.v(TAG, "startVideoPlayback");
    holder.setFixedSize(mVideoWidth, mVideoHeight);
    mMediaPlayer.start();
}

错误:01-05 21:10:59.640:错误/MediaPlayerDemo(15989):无效的视频宽度(0)或高度(0)

4

2 回答 2

1

将 onVideoSizeChanged(...) 函数更改为:-

public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
        Log.d("onVideoSizeChanged: (%dx%d)", width, height);
        mVideoWidth = mp.getVideoWidth();
        mVideoHeight = mp.getVideoHeight();
        mVideoAspectRatio = mp.getVideoAspectRatio();
        if (mVideoWidth != 0 && mVideoHeight != 0)
            setVideoLayout(mVideoLayout, mAspectRatio);
    }
于 2013-01-07T04:47:20.317 回答
0
public void onVideoSizeChanged(MediaPlayer mp, int width, int height)
{
    if(width == 0 || height == 0) {
        return;
    }

    this.width = width;
    this.height = height;
    aspectRatio = width/height;

    startVideoPlayback();
}

我建议你这样做。

在 onPrepared 方法内部替换startVideoPlayback()mediaPlayer.start()

于 2013-01-05T16:35:49.293 回答