Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android開發 >> 關於android開發 >> 使用VideoView播放、暫停、快進視頻,videoview快進

使用VideoView播放、暫停、快進視頻,videoview快進

編輯:關於android開發

使用VideoView播放、暫停、快進視頻,videoview快進


1 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 tools:context="com.example.videoview.MainActivity" > 6 7 <VideoView 8 android:id="@+id/videoView" 9 android:layout_width="match_parent" 10 android:layout_height="416dp" /> 11 12 <LinearLayout 13 android:id="@+id/linearLayout" 14 android:layout_width="match_parent" 15 android:layout_height="wrap_content" 16 android:layout_gravity="bottom" 17 android:orientation="horizontal" > 18 19 <Button 20 android:id="@+id/start" 21 android:layout_width="wrap_content" 22 android:layout_height="wrap_content" 23 android:text="開始" /> 24 25 <Button 26 android:id="@+id/pause" 27 android:layout_width="wrap_content" 28 android:layout_height="wrap_content" 29 android:text="暫停" /> 30 31 <Button 32 android:id="@+id/seekto" 33 android:layout_width="wrap_content" 34 android:layout_height="wrap_content" 35 android:text="3秒處" /> 36 </LinearLayout> 37 38 </FrameLayout> activity_main.xml

測試主代碼:

 1 package com.example.videotest;
 2 
 3 import java.io.File;
 4 
 5 import android.app.Activity;
 6 import android.os.Bundle;
 7 import android.os.Environment;
 8 import android.provider.MediaStore.Video;
 9 import android.view.Menu;
10 import android.view.MenuItem;
11 import android.view.View;
12 import android.view.View.OnClickListener;
13 import android.widget.Button;
14 import android.widget.VideoView;
15 
16 public class MainActivity extends Activity implements OnClickListener {
17 
18     private VideoView videoView;
19 
20     @Override
21     protected void onCreate(Bundle savedInstanceState) {
22         super.onCreate(savedInstanceState);
23         setContentView(R.layout.activity_main);
24 
25         videoView = (VideoView) findViewById(R.id.videoView);
26 
27         File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
28 
29         File f = new File(path, "/Camera/test.mp4");
30 
31         videoView.setVideoPath(f.getAbsolutePath());
32 
33         Button start = (Button) findViewById(R.id.start);
34         start.setOnClickListener(this);
35         Button pause = (Button) findViewById(R.id.pause);
36         pause.setOnClickListener(this);
37         Button seekto = (Button) findViewById(R.id.seekto);
38         seekto.setOnClickListener(this);
39 
40     }
41 
42     @Override
43     public void onClick(View v) {
44         switch (v.getId()) {
45         case R.id.start:
46             videoView.start();
47             break;
48         case R.id.pause:
49             videoView.pause();
50             break;
51         case R.id.seekto:
52             videoView.seekTo(3*1000);
53             break;
54         }
55     }
56 
57 }

 

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved