每天进步一点----- VideoView
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了每天进步一点----- VideoView相关的知识,希望对你有一定的参考价值。
package com.example.playvideotest; import java.io.File; import android.os.Bundle; import android.os.Environment; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.VideoView; import android.app.Activity; public class MainActivity extends Activity implements OnClickListener { private VideoView videoView; private Button play; private Button pause; private Button replay; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); play = (Button) findViewById(R.id.play); pause = (Button) findViewById(R.id.pause); replay = (Button) findViewById(R.id.replay); videoView = (VideoView) findViewById(R.id.video_view); play.setOnClickListener(this); pause.setOnClickListener(this); replay.setOnClickListener(this); initVideoPath(); } private void initVideoPath() { File file = new File(Environment.getExternalStorageDirectory(), "movie.3gp"); videoView.setVideoPath(file.getPath()); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.play: if (!videoView.isPlaying()) { videoView.start(); } break; case R.id.pause: if (videoView.isPlaying()) { videoView.pause(); } break; case R.id.replay: if (videoView.isPlaying()) { videoView.resume(); } break; } } @Override protected void onDestroy() { super.onDestroy(); if (videoView != null) { videoView.suspend(); } } }
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <VideoView android:id="@+id/video_view" android:layout_width="match_parent" android:layout_height="wrap_content" /> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:id="@+id/play" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="Play" /> <Button android:id="@+id/pause" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="Pause" /> <Button android:id="@+id/replay" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="Replay" /> </LinearLayout> </LinearLayout>
以上是关于每天进步一点----- VideoView的主要内容,如果未能解决你的问题,请参考以下文章
[每天进步一点点~] uni-app css 制作雷达扫描、波浪移动动画效果