【发布时间】:2014-06-09 17:56:49
【问题描述】:
我正在练习一个项目,我想在其中播放多种格式的视频。 我在谷歌上搜索了很多,也找到了很多代码的链接。我尝试了很多代码,但没有一个对我有用
我从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();
}
}
【问题讨论】: