我在mediaplayer中播放視頻時遇到問題。我有一個聲音,但沒有視頻。我嘗試了一切,找不到解決辦法。或者,也許你知道如何在videoview中播放sdp文件?下面的代碼:沒有視頻媒體播放器
public class TestStream1 extends Activity implements Callback{
MediaPlayer mMediaPlayer;
String SrcPath = "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov";
private SurfaceView mPreview;
private SurfaceHolder holder;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mPreview = (SurfaceView) findViewById(R.id.surface);
holder = mPreview.getHolder();
holder.addCallback(TestStream1.this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
holder.setFixedSize(400,300);
mMediaPlayer = new MediaPlayer();
try{
mMediaPlayer.setDataSource(SrcPath);
mMediaPlayer.setDisplay(holder);
mMediaPlayer.prepare();
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mMediaPlayer.start();
}catch(Exception e){
Toast .makeText(TestStream1.this, "Fail", Toast.LENGTH_LONG).show();
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
}
}
編輯:佈局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<SurfaceView
android:id="@+id/surface"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
</LinearLayout>
我試圖在videoView中做同樣的事情,它的工作原理有聲音和視頻。唯一的問題是媒體播放器。 mediaplayer和videoview使用相同的編解碼器嗎? – 2012-03-27 12:46:49
是的,他們使用同一個媒體播放器。 VideoView只是surfaceHolder的包裝,非常方便。這意味着代碼需要檢查。如果可以,你可以去videoView。發佈你的佈局xml如果你不想要,我們將嘗試糾正代碼。 :) – Akhil 2012-03-27 17:06:35
我的意思是如果你不想使用視頻視圖,並繼續與表面視圖 – Akhil 2012-03-27 17:48:13