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);
如果没有必要然后将其删除的视频将有声播放。否则,请写下你真正想要做的视频播放。