2013-01-05 165 views
0

我需要爲這兩種視頻音頻播放android rtsp流。但不管我做什麼,他們只是不開始。視頻的rstp流爲.mp4格式,音頻爲.mp3。該流在VLC中播放時效果很好,並且顯示的分辨率爲320X240。但這裏只是給出了我在底部發布的錯誤。也請告訴如何流式傳輸mp3,因爲在android-sdk的API演示中沒有教程。該視頻可與Vitamio Library一起使用。但我不知道如何定製它。在Android上播放rtsp流

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:ERROR/MediaPlayerDemo(15989):無效視頻寬度(0)或高度(0)

+0

請問這個'mIsVideoSizeKnown'到是真的嗎? 「mVideoWidth」或「mVideoHeight」在哪裏設置?此外logcat是鈍的,寬度或高度是0! – t0mm13b

+0

ipinak OnBufferingUpdateListener,OnCompletionListener, OnPreparedListener,OnVideoSizeChangedListener,SurfaceHolder.Callback –

+0

t0mm13b這不是真的這就是爲什麼視頻沒有播放。我只是使用由android-sdk提供的API演示btw –

回答

1

更改替換startVideoPlayback()的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); 
    } 
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法mediaPlayer.start()

+0

Didnt work 01-05 21:47:37.000:ERROR/MediaPlayerDemo(18711):無效視頻寬度(0)或高度(0) 01-05 21:47:37.906:錯誤/ MediaPlayer(18711):錯誤(1,-2147483648) 01-05 21:47:37.910:錯誤/ MediaPlayer(18711):錯誤(1,-2147483648) –

+0

您可以更改爲mediaPlayer.prepareAsync();而不是mediaPlayer.prepare();雖然,我不確定這是否真的很重要。 – ipinak

+0

更改了它,但出現了相同的3個錯誤.... –