我目前正在使用此代码播放音频和视频文件,但我需要能够在30秒的特定时间范围后停止视频/音频文件。是否有可能使用videoview和我一直尝试但未成功的mediacontroller。
有人可以给我一些可以执行此功能的代码片段。
public class AudioActivity extends Activity {
TextView audioTitleValue;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/** REMOVE TITLE **/
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.moveplay);
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
final VideoView audioView = (VideoView) findViewById(R.id.VideoView);
final MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(audioView);
Bundle extras = getIntent().getExtras();
String pathfile = extras.getString("key");
Log.v("key = ",pathfile);
Uri audio = Uri.parse(pathfile);
audioView.setMediaController(mediaController);
audioView.setVideoURI(audio);
audioView.start();
}
}
和关联的xml文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="35dp" >
<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:paddingLeft="25dp"
android:paddingTop="7dp"
android:text="@string/app_name"
android:textColor="#999999" />
</LinearLayout>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="35dp"
android:src="@drawable/musicplayergraphic" />
<VideoView
android:id="@+id/VideoView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</VideoView>