Android使用VideoView播放本地视频及网络视频Demo
生活随笔
收集整理的這篇文章主要介紹了
Android使用VideoView播放本地视频及网络视频Demo
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
?1.xm文件
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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"tools:context="com.zmsoft.TestTool.activity.ZhiboActivity"><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"><VideoViewandroid:id="@+id/videoView"android:layout_width="match_parent"android:layout_height="match_parent"/></RelativeLayout></RelativeLayout>2.寫一個(gè)類集成??AppCompatActivity
package com.zmsoft.TestTool.activity;import android.media.MediaPlayer; import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import android.widget.MediaController; import android.widget.Toast; import android.widget.VideoView;import com.zmsoft.TestTool.R; import com.zmsoft.TestTool.utils.Utils;/*** Created by hanbao0928 on 2018/3/30.*/public class ZhiboActivity extends AppCompatActivity {private VideoView videoView ;@Overrideprotected void onCreate(@Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.receice_log);//本地的視頻 需要在手機(jī)SD卡根目錄添加一個(gè) fl1234.mp4 視頻String videoUrl1 = Environment.getExternalStorageDirectory().getPath()+"/fl1234.mp4" ;//網(wǎng)絡(luò)視頻String videoUrl2 = Utils.videoUrl ;Uri uri = Uri.parse( videoUrl2 );videoView = (VideoView)this.findViewById(R.id.videoView );//設(shè)置視頻控制器videoView.setMediaController(new MediaController(this));//播放完成回調(diào)videoView.setOnCompletionListener( new MyPlayerOnCompletionListener());//設(shè)置視頻路徑videoView.setVideoURI(uri);//開始播放視頻videoView.start();}class MyPlayerOnCompletionListener implements MediaPlayer.OnCompletionListener {@Overridepublic void onCompletion(MediaPlayer mp) {Toast.makeText( ZhiboActivity.this, "播放完成了", Toast.LENGTH_SHORT).show();}} }3.寫一個(gè)?Utils? 類用于存放網(wǎng)絡(luò)視頻鏈接地址
package com.zmsoft.TestTool.utils;/*** Created by hanbao0928 on 2018/3/30.*/public class Utils {// public static final String videoUrl = "http://www.pps.tv/w_19rqylpzsh.mp4" ;public static final String videoUrl = "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" ;//public static final String videoUrl = "http://gslb.miaopai.com/stream/ed5HCfnhovu3tyIQAiv60Q__.mp4" ; }以上則是一個(gè)簡單的 Android??VideoView 實(shí)現(xiàn)本地及其網(wǎng)路視頻播放完整Demo,如有疑問請留言,謝謝 !!!
轉(zhuǎn)載于:https://www.cnblogs.com/monkey0928/p/8675942.html
總結(jié)
以上是生活随笔為你收集整理的Android使用VideoView播放本地视频及网络视频Demo的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ORM 关系对象映射 基础知识点
- 下一篇: JAVA集合框架包含的内容