流沙团
播放器测试编写
2016-9-11 流沙团


0x001 控件设置



加入VideoView控件



 <VideoView 
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/vv"

/>







0x002  设置activity的样式



要求横屏,并且 去掉 标题栏



<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar" >
<activity
android:name="com.gyarmy.media.MainActivity"
android:label="@string/app_name"
android:screenOrientation="landscape"
>







0x003  播放文件



要求, 加入控制栏







package com.gyarmy.media;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.MediaController;
import android.widget.VideoView;

public class MainActivity extends Activity {

private VideoView vv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

//设置ID
vv = (VideoView) findViewById(R.id.vv);
MediaController mc = new MediaController(this);
mc.setAnchorView(vv);

//设置视频
vv.setMediaController(mc);
vv.setVideoPath("/mnt/shared/Other/xinli.mp4");

vv.start();
}

@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;
}

}









发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容