-1
我想在啓動Android應用程序時播放視頻文件。我試過了,但它不能正常工作。我收到一條錯誤消息,它告訴我們視頻無法播放。我已將我的視頻(.mp4擴展名)保存在原始文件夾中。我已經設置了以下路徑:如何在啓動Android應用程序時添加視頻文件
path = "android.resource://com.easy.video/" + R.raw.myvideo;
這是我的java文件。
package com.easy.video;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.widget.Toast;
import android.widget.VideoView;
@SuppressWarnings("unused")
public class MainActivity extends Activity {
private VideoView videoView;
String extStorageDirectory;
protected static final int PLAY = 0x101;
protected static final int STOP = 0x102;
protected static final int PAUSE = 0x103;
int State;
private String current;
private String path;
private VideoView mVideoView;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.activity_main);
path = "android.resource://com.easy.video/" + R.raw.myvideo;
mVideoView = (VideoView) findViewById(R.id.video);
if (path == null || path.length() == 0) {
Toast.makeText(MainActivity.this, "File URL/path is empty",
Toast.LENGTH_LONG).show();
} else {
// If the path has not changed, just start the media player
if (path.equals(current) && mVideoView != null) {
mVideoView.start();
mVideoView.requestFocus();
return;
}
current = path;
mVideoView.setVideoPath(path);
mVideoView.start();
mVideoView.requestFocus();
}
mVideoView.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer arg0) {
Intent in = new Intent(MainActivity.this, NextActivity.class);
startActivity(in);
finish();
}
});
}
}
其實我不確定它是否正確。 如果有人能夠如此友好地解釋如何做到這一點,我將不勝感激。
你的問題不清楚,有價值。 – 2013-05-13 05:50:58