我正在练习一个项目,我想播放多种格式的视频。 我在google上搜索了这么多,并且还有很多代码的链接。我尝试了很多代码,但没有一个能为我工作
我从这个link尝试了这个代码,但它对我不起作用 因此,任何人都可以建议我必须从哪里开始研究 这样我就可以播放多种格式的视频
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".VideoPlayerActivity" >
<FrameLayout
android:id="@+id/video_frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<VideoView
android:id="@+id/video_player_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
</RelativeLayout>
public class VideoPlayerActivity extends Activity {
VideoView video_player_view;
DisplayMetrics dm;
SurfaceView sur_View;
MediaController media_Controller;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void getInit() {
video_player_view = (VideoView) findViewById(R.id.video_player_view);
media_Controller = new MediaController(this);
dm = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(dm);
int height = dm.heightPixels;
int width = dm.widthPixels;
video_player_view.setMinimumWidth(width);
video_player_view.setMinimumHeight(height);
video_player_view.setMediaController(media_Controller);
video_player_view.setVideoPath("/sdcard/Bottle.mp4");
video_player_view.start();
}
}
答案 0 :(得分:0)
首先定义ProgressDialog mProgressDialog;
然后尝试这段代码,它对我有用:
video = (VideoView) findViewById(R.id.VideoView1);
final MediaController mc = new MediaController(this);
mc.setAnchorView(video);
mc.setMediaPlayer(video);
Uri uri = Uri.parse(path1);
video.setMediaController(mc);
System.out.println("!-- uri: "+uri.toString());
video.setVideoURI(uri);
video.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mProgressDialog.dismiss();
}
});
video.start();
video.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
}
});
}
public void showLoaderProgress(){
mProgressDialog = new ProgressDialog(this);
mProgressDialog.setMessage("Loading Video\nPlease wait...");
mProgressDialog.setIndeterminate(true);
mProgressDialog.setCancelable(false);
mProgressDialog.show();
}
其中path1是您的视频路径。