0
這裏是我的代碼播放視頻。但視頻停留在我的屏幕上,並且不播放。有沒有解決方法?視頻不播放,但音頻偵聽
這裏是我的代碼播放視頻。但視頻停留在我的屏幕上,並且不播放。有沒有解決方法?視頻不播放,但音頻偵聽
video_player_view.xml
<?xml version="1.0" encoding="utf-8"?>
<VideoView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/VideoPlayerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Java code:
public class VideoPlayerActivity extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video_player_view);
String video_file_path = ?;//give the path of your video
VideoView video_view = (VideoView) this.findViewById(R.id.VideoPlayerView);
MediaController mc = new MediaController(this);
video_view.setMediaController(mc);
video_view.setVideoPath(video_file_path);
video_view.requestFocus();
// start video
video_view.start();
video_view.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
endActivity();
}
});
}
public void endActivity() {
this.finish();
}
}
你爲什麼使用這段代碼?
Intent tostart = new Intent(Intent.ACTION_VIEW);
startActivity(tostart);
如果沒有必要然後將其刪除的視頻將有聲播放。否則,請寫下你真正想要做的視頻播放。