我試圖開發一個應用程序,它嵌入了很多視頻,我想調用Android的媒體播放器,VideoView對象上的視頻。但是,我得到這些奇怪的錯誤:安卓媒體播放器不工作
- I/MediaPlayer的(2874):信息(1,26)
- E/MediaPlayer的(2874):錯誤(-4,-4)
- d/VideoView(2874):錯誤:-4,-4
當我嘗試播放mp4視頻或其他3gp視頻時,未從我的手機錄製。我的代碼是這樣的:
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.MediaController;
import android.widget.VideoView;
public class PlayTest2 extends Activity{
private MediaController ctlr;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.test2);
try {
VideoView video = (VideoView) findViewById(R.id.test2);
// Load and start the movie
video.setVideoPath("android.resource://com.example.child.protector/raw/output");
ctlr=new MediaController(this);
ctlr.setMediaPlayer(video);
video.setMediaController(ctlr);
video.start();
//video.requestFocus();//this line is new
}
catch (Exception e) {
Log.e("---------- this is my app --------", "error: " + e.getMessage(), e);
}
}
}
和我的佈局是一樣的東西:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<VideoView
android:id="@+id/test2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
/>
</FrameLayout>
有什麼錯我的代碼?
我知道我的文件在那裏和所有。我用3GP視頻示例運行了這段代碼,它工作得很好(但是我從手機錄製了視頻並將其複製到我的計算機,然後重新打包到我的應用程序中,位於Eclipse中的/ res/raw文件夾下)。不過,問題是由於某種原因,我的媒體播放器只能播放特定的3GPP文件。如果我嘗試使用MobileMediaConverter將MP4轉換爲3GP,則會在我的筆記本電腦上播放,但不會在此應用中播放。另外請注意,如果我打開視頻作爲文件(換句話說,調用我的三星Galaxy S手機上的默認視頻播放器),它工作得很好(意味着我的手機具有這些功能)。所以我想知道:
- 這是代碼有問題嗎?
- 這是更多的轉換mp4到3gp錯誤?
任何幫助將不勝感激。謝謝!!