自定义视频播放(原生)
来源:互联网 发布:网络空间安全考研排名 编辑:程序博客网 时间:2024/05/18 23:57
使用原生的VideoView、MadielView
自定义VideoView:
package com.whzg.zbjy.utils;import android.content.Context;import android.util.AttributeSet;import android.widget.VideoView;public class CustomVideoView extends VideoView{ private PlayPauseListener mListener; public CustomVideoView (Context context) { super (context); } public CustomVideoView (Context context, AttributeSet attrs) { super (context, attrs); } public CustomVideoView (Context context, AttributeSet attrs, int defStyle) { super (context, attrs, defStyle); } public void setPlayPauseListener (PlayPauseListener listener) { mListener = listener; } @Override public void pause () { super.pause (); if (mListener != null) { mListener.onPause (); } } @Override public void start () { super.start (); if (mListener != null) { mListener.onPlay (); } } public interface PlayPauseListener { void onPlay(); void onPause(); }}
自定义播放界面:
使用intent传url
Intent intent = new Intent(getActivity(), ShowVideoAct.class);
intent.putExtra(ShowVideoAct.URL, “url”);
startActivity(intent);
package com.whzg.zbjy.ui;import android.app.Activity;import android.net.Uri;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.MediaController;import android.widget.TextView;import com.whzg.zbjy.R;import com.whzg.zbjy.utils.CustomVideoView;public class ShowVideoAct extends Activity{ public static final String URL = "url"; private Button btnBack; private CustomVideoView vv; private TextView tv; @Override protected void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView (R.layout.show_video); String url = getIntent().getStringExtra (URL); vv = (CustomVideoView)findViewById (R.id.video_show_video); tv = (TextView)findViewById (R.id.tv_show_video_loading_video); Uri uri = Uri.parse (url); vv.setMediaController (new MediaController (this)); vv.setVideoURI (uri); vv.start (); vv.setPlayPauseListener (new CustomVideoView.PlayPauseListener () { @Override public void onPlay () { tv.setVisibility (View.GONE); } @Override public void onPause () { } }); // vv.requestFocus();//加载完之后等待,用户点击播放 }}
布局文件:
<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#000" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center_horizontal" android:orientation="vertical" > <com.whzg.zbjy.utils.CustomVideoView android:id="@+id/video_show_video" android:layout_width="wrap_content" android:layout_height="fill_parent" /> </LinearLayout> <TextView android:id="@+id/tv_show_video_loading_video" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_marginTop="44dp" android:background="#5000" android:gravity="center" android:text="加载中..." android:textColor="#fff" android:textSize="20sp" /></FrameLayout>
0 0
- 自定义视频播放(原生)
- OC原生视频播放
- Android原生视频播放器
- android 视频播放(一)利用android原生的videoview
- 关于android原生视频播放(转载集合之一)
- 关于android原生视频播放(转载集合之二)
- 自定义视频播放器
- 视频播放自定义控制器
- 自定义视频播放器
- 自定义视频播放器
- 自定义视频播放器
- ios9 苹果原生视频播放器
- unity调用ios原生视频播放
- MediaPlayer封装原生视频播放器
- android自定义视频播放器
- html---自定义视频播放控制台
- AVPlayer自定义视频播放器
- iOS 自定义视频播放器
- linux sheel脚本里面,在if语句里“$? -eq o” 这是什么意思!!!
- 秒杀后台系统设计
- 在vue项目中前端生成二维码应该注意的问题
- 随机产生一个整数
- android 二维码 Zxing记录
- 自定义视频播放(原生)
- 控制台访问模型
- Volume of Mesh Calculation With WebGL
- missing artifact jdk.tools:jar:1.7
- linux shell 中的sleep命令
- STM32在KEIL4.7下生成BIN文件
- Android AlarmManager实现不间断轮询服务
- Memcached 笔记与总结(6)PHP 实现 Memcached 的一致性哈希分布算法
- iOS开发内存优化-问题代码定位