使用VideoView播放视频
2015-04-11 16:23
393 查看
添加权限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>布局:
/VedioViewTest/res/layout/activity_main.xml
<pre name="code" class="html"><LinearLayout 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"
>
<VideoView
android:id="@+id/video"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
/VedioViewTest/src/com/lxm/vedioviewtest/MainActivity.java
package com.lxm.vedioviewtest;
import java.io.File;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.view.Menu;
import android.widget.MediaController;
import android.widget.VideoView;
public class MainActivity extends Activity {
VideoView videoView;
MediaController mController;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
videoView = (VideoView) findViewById(R.id.video);
mController = new MediaController(this);
//记得修改路径
String mp4Path = Environment.getExternalStorageDirectory()+"/mv";
File video = new File(mp4Path+"/Roar.mp4");
if(video.exists()){
videoView.setVideoPath(video.getAbsolutePath());
videoView.setMediaController(mController);
// 设置mController与videoView建立关联
mController.setMediaPlayer(videoView);
videoView.requestFocus();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
源码下载
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>布局:
/VedioViewTest/res/layout/activity_main.xml
<pre name="code" class="html"><LinearLayout 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"
>
<VideoView
android:id="@+id/video"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
/VedioViewTest/src/com/lxm/vedioviewtest/MainActivity.java
package com.lxm.vedioviewtest;
import java.io.File;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.view.Menu;
import android.widget.MediaController;
import android.widget.VideoView;
public class MainActivity extends Activity {
VideoView videoView;
MediaController mController;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
videoView = (VideoView) findViewById(R.id.video);
mController = new MediaController(this);
//记得修改路径
String mp4Path = Environment.getExternalStorageDirectory()+"/mv";
File video = new File(mp4Path+"/Roar.mp4");
if(video.exists()){
videoView.setVideoPath(video.getAbsolutePath());
videoView.setMediaController(mController);
// 设置mController与videoView建立关联
mController.setMediaPlayer(videoView);
videoView.requestFocus();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
源码下载
相关文章推荐
- 在Android中使用VideoView播放视频
- 简单使用videoview播放视频
- Android--使用VideoView播放视频以及VideoView的api
- 使用videoView来播放视频
- 在Android中使用VideoView播放视频
- 初学Android,多媒体之使用VideoView播放视频(七十七)
- Android使用VideoView播放网络视频
- 在Android中使用VideoView播放视频
- Android使用VideoView播放网络视频
- 使用VideoView播放视频
- Android使用VideoView播放当前工程中的视频文件
- 27、从头学Android之多媒体--使用VideoView播放视频
- Android使用VideoView播放网络视频
- Android使用VideoView播放网络视频
- Android使用VideoView播放网络视频
- Android使用VideoView播放网络视频
- 使用VideoView播放视频
- Android使用videoview播放res/raw下的视频并在结束后隐藏
- Android使用VideoView播放网络视频
- Android--使用VideoView播放视频