使用VideoView自定義控制面板怎么實(shí)現(xiàn)視頻播放器?相信很多沒有經(jīng)驗(yàn)的人對此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。
為肅南裕固族自治等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計制作服務(wù),及肅南裕固族自治網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為做網(wǎng)站、網(wǎng)站建設(shè)、肅南裕固族自治網(wǎng)站設(shè)計,以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會得到認(rèn)可,從而選擇與我們長期合作。這樣,我們也可以走得更遠(yuǎn)!
項目用到的技術(shù)點(diǎn)和亮點(diǎn)
VideoView封裝視頻播放工具類
自定義視頻控制面板
手勢識別器的使用
1. VideoView封裝視頻播放工具類
視頻播放這些其實(shí)都挺簡單的,VideoView這個類都提供了相應(yīng)方法,詳細(xì)見代碼 代碼都比較簡單,不過需要注意的是要在主線程中更新視頻面板的UI信息。
package com.zlc.video; import android.app.Activity; import android.content.Context; import android.content.pm.ActivityInfo; import android.media.MediaPlayer; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.PowerManager; import android.os.PowerManager.WakeLock; import android.util.Log; import android.view.View; import android.widget.ImageView; import android.widget.VideoView; public class VideoBusiness implements MediaPlayer.OnPreparedListener,MediaPlayer.OnCompletionListener,MediaPlayer.OnErrorListener{ private Activity activity; private WakeLock mWakeLock; public VideoView mVideoView; private VideoController mController; /**播放狀態(tài)枚舉,有三種播放狀態(tài):空閑,正在準(zhǔn)備*/ private enum PLAYER_STATUS { IDLE, PREPARING,PAUSED, PREPARED,RESUMED,STOPPED } /**當(dāng)前播放狀態(tài)*/ public PLAYER_STATUS mPlayerStatus = PLAYER_STATUS.IDLE; /**播放信息異步處理方法,用于更新進(jìn)度*/ /**事件標(biāo)志*/ private int mLastPos; public VideoBusiness(Activity activity){ this.activity = activity; // 保持屏幕高亮 PowerManager pm = (PowerManager) activity.getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "Test"); } //初始化視頻播放器 public void initVideo(VideoView videoView,VideoController controller,String sourceUrl){ this.mVideoView = videoView; this.mController = controller; mController.setVideoBusiness(this); Log.e("msg","設(shè)置播放地址 = "+sourceUrl); mVideoView.setOnPreparedListener(this); mVideoView.setOnCompletionListener(this); mVideoView.setOnErrorListener(this); mVideoView.setVideoPath(sourceUrl); //設(shè)置播放地址 } //開始播放 public void startPlay(){ if (null != mWakeLock && (!mWakeLock.isHeld())) { mWakeLock.acquire(); } if(null != mVideoView) { Log.e("msg", "播放"); mVideoView.start(); mPlayerStatus = PLAYER_STATUS.PREPARING; } } /** * 暫停播放 */ public void pause() { if (null != mWakeLock) { mWakeLock.release(); } if(null != mVideoView && mVideoView.isPlaying()){ mVideoView.pause(); mPlayerStatus = PLAYER_STATUS.PAUSED; mLastPos = getCurrentTime(); } } /** * 繼續(xù)播放 */ public void resume(){ if (null != mWakeLock) { mWakeLock.acquire(); } if(null != mVideoView){ //mVideoView.resume(); mVideoView.seekTo(mLastPos); mVideoView.start(); mPlayerStatus = PLAYER_STATUS.RESUMED; } } /** * 停止播放 */ public void stop() { if (null != mWakeLock) { mWakeLock.release(); } if(null != mVideoView){ mLastPos = getCurrentTime(); mVideoView.stopPlayback(); mPlayerStatus = PLAYER_STATUS.STOPPED; } } /** * 判斷是否正在播放 * @return */ public boolean isPlaying(){ return mVideoView!=null && mVideoView.isPlaying(); } /** * 是否暫停 */ public boolean isPause(){ return mPlayerStatus == PLAYER_STATUS.PAUSED; } /** * 釋放資源 */ public void release(){ if (null != mWakeLock) { mWakeLock.release(); mWakeLock = null; } if(null != mVideoView){ mVideoView.stopPlayback(); mVideoView = null; } } @Override public void onCompletion(MediaPlayer mediaPlayer) { Log.e("onCompletion","視頻播放完了"); mController.showLong(); mController.setProgress(0); mLastPos = 0; mPlayerStatus = PLAYER_STATUS.IDLE; removeUIMessage(); } @Override public boolean onError(MediaPlayer mediaPlayer, int i, int i1) { Log.e("onError","視頻播放報錯了"); return false; } @Override public void onPrepared(MediaPlayer mediaPlayer) { Log.e("onPrepared","視頻準(zhǔn)備好了"); if (mPlayerStatus!= PLAYER_STATUS.PAUSED){ int totalTime = getTotalTime(); mController.setTotalTime(totalTime); mController.setProgress(0); mController.setMaxProgress(totalTime); mPlayerStatus = PLAYER_STATUS.PREPARED; sendUIMessage(); } } /** * 進(jìn)度條拖拽播放 * @param time */ public void seekToPlay(int time){ int totalSecond = getTotalTime(); int tempTime = time > totalSecond ? totalSecond : time; mVideoView.seekTo(tempTime); sendUIMessage(); } //視頻暫停播放 播放大按鈕點(diǎn)擊事件 public void playVideo(ImageView id_btn_video_play, ImageView img){ if(isPlaying()){ pause(); id_btn_video_play.setVisibility(View.VISIBLE); img.setImageResource(R.drawable.video_pause); mPlayerStatus = PLAYER_STATUS.PAUSED; mUIHandler.sendEmptyMessageDelayed(UI_EVENT_UPDATE_CURRPOSITION, 500); }else if(isPause()){ resume(); id_btn_video_play.setVisibility(View.GONE); img.setImageResource(R.drawable.video_play); mPlayerStatus = PLAYER_STATUS.RESUMED; }else{ img.setImageResource(R.drawable.video_play); id_btn_video_play.setVisibility(View.GONE); startPlay(); mPlayerStatus = PLAYER_STATUS.PREPARING; } } private boolean isCurrentLandscape = false; //是不是橫屏 //橫豎屏切換按鈕點(diǎn)擊方法 public void toggleScreenDir(View v){ if (isCurrentLandscape) {// 如果當(dāng)前是橫屏,則切換為豎屏,然后把按鈕為變?yōu)樽兇蟮膱D標(biāo) activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); if(v instanceof ImageView){ ((ImageView)v).setImageResource(R.drawable.zuidahua_2x); } } else {// 如果當(dāng)前是豎屏,則切換為橫屏,然后把按鈕為變?yōu)樽冃〉膱D標(biāo) activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); if(v instanceof ImageView){ ((ImageView)v).setImageResource(R.drawable.xiaohua_2x); } } isCurrentLandscape = !isCurrentLandscape; } public UIHandler mUIHandler = new UIHandler(Looper.getMainLooper()); public final int UI_EVENT_UPDATE_CURRPOSITION = 1; //更新進(jìn)度信息 public boolean isSeekBarEnable = true; class UIHandler extends Handler{ public UIHandler(Looper mainLooper) { super(mainLooper); } @Override public void handleMessage(Message msg) { switch (msg.what) { //更新進(jìn)度及時間 case UI_EVENT_UPDATE_CURRPOSITION: if (isSeekBarEnable) { int currentPosition = getCurrentTime(); String timeString = mController.getTimeString(currentPosition); //Log.e("handleMessage",timeString); if(isPlaying()) { mController.setProgress(currentPosition); mUIHandler.sendEmptyMessageDelayed( UI_EVENT_UPDATE_CURRPOSITION, 200); } } break; } } } public void sendUIMessage(){ mUIHandler.sendEmptyMessage(UI_EVENT_UPDATE_CURRPOSITION); } public void removeUIMessage(){ mUIHandler.removeMessages(UI_EVENT_UPDATE_CURRPOSITION); } //獲取視頻總時間 public int getTotalTime(){ return mVideoView==null ? 0 : mVideoView.getDuration(); } //獲取視頻當(dāng)前時間 public int getCurrentTime(){ return mVideoView==null ? 0 : mVideoView.getCurrentPosition(); } }
2. 手勢識別器的使用
//1. 創(chuàng)建手勢識別器 progressGestureDetector = new GestureDetector(mContext,new ProgressGestureListenr()); //2.復(fù)寫GestureDetector.OnGestureListener的6個方法 boolean onDown(MotionEvent e) //用戶按下屏幕就會觸發(fā) void onShowPress(MotionEvent e) ////down事件發(fā)生而move或則up還沒發(fā)生前觸發(fā)該事件 boolean onSingleTapUp(MotionEvent e) //一次點(diǎn)擊up事件 boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) //在屏幕上拖動事件 void onLongPress(MotionEvent e) //長按事件 boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) //滑動手勢事件 //3 onTouch中攔截 @Override public boolean onTouch(View view, MotionEvent event) { return progressGestureDetector.onTouchEvent(event); } //4 事件綁定 progressArea.setOnTouchListener(this);
3. 自定義視頻控制面板
代碼比較簡單同時代碼不長 都有注釋 需要的可以參考下 大神勿噴
package com.zlc.video; import android.app.Activity; import android.content.Context; import android.media.AudioManager; import android.os.Handler; import android.os.Message; import android.provider.Settings; import android.util.AttributeSet; import android.util.Log; import android.view.GestureDetector; import android.view.MotionEvent; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.RelativeLayout; import android.widget.SeekBar; import android.widget.TextView; import com.zlc.video.utils.DensityUtil; import com.zlc.video.utils.ScreenUtil; import java.text.SimpleDateFormat; import java.util.Date; public class VideoController extends RelativeLayout implements View.OnTouchListener,View.OnClickListener,SeekBar.OnSeekBarChangeListener{ private Context mContext; private View mContainer; private VideoBusiness videoBusiness; /** 表示當(dāng)前視頻控制面板是否展示*/ public boolean isShow = true; private Handler hideHandler = new Handler() { @Override public void handleMessage(Message msg) { if (isShow) { hideController(); } } }; /** 視頻功能控制底邊欄*/ private LinearLayout mMediaController; /***************手勢相關(guān)*********************/ private int GESTURE_FLAG = 0;//1調(diào)節(jié)進(jìn)度,2調(diào)節(jié)音量,3調(diào)節(jié)亮度 private FrameLayout mProgressIndicator; private ProgressBar progressBar; /**進(jìn)度相關(guān)*/ private GestureDetector progressGestureDetector; private static final int GESTURE_MODIFY_PROGRESS = 1; /**音量相關(guān)*/ private static final int GESTURE_MODIFY_VOLUME = 2; private AudioManager audiomanager; private int maxVolume, currentVolume; /**亮度相關(guān)*/ private static final int GESTURE_MODIFY_BRIGHTNESS = 3; private WindowManager.LayoutParams brightnessLp; private int maxBrightness,currentBrightness; private LinearLayout progressArea; private int targetTime; //UI相關(guān) private RelativeLayout id_rl_video_controller; private FrameLayout id_fl_video_play; private FrameLayout id_fl_video_expand; private TextView id_video_time; private TextView id_video_totaltime; private SeekBar id_sb_progress; private ImageView id_btn_video_play; private ImageView id_iv_video_play; private TextView id_tv_video_info; public VideoController(Context context) { this(context, null); } public VideoController(Context context, AttributeSet attrs) { this(context, attrs, 0); } public VideoController(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mContext = context; init(); initListener(); } private void init() { //初始化音量相關(guān) audiomanager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE); maxVolume = audiomanager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); // 獲取系統(tǒng)最大音量 currentVolume = audiomanager.getStreamVolume(AudioManager.STREAM_MUSIC); // 獲取當(dāng)前值 //初始化亮度相關(guān) brightnessLp=((Activity)mContext).getWindow().getAttributes(); currentBrightness = getCurrentBrightness(); maxBrightness = 255; //設(shè)置最大亮度 initView(); } private void initView() { mContainer = View.inflate(mContext, R.layout.video_controller, null); id_rl_video_controller = findView(R.id.id_rl_video_controller); mMediaController = findView(R.id.id_ll_controller); mProgressIndicator = findView(R.id.id_fl_progress_indicator); progressBar = findView(R.id.id_pb_gesture_progress); progressArea = findView(R.id.id_ll_video_gesture_progress); id_fl_video_play = findView(R.id.id_fl_video_play); id_fl_video_expand = findView(R.id.id_fl_video_expand); id_video_time = findView(R.id.id_video_time); id_video_totaltime = findView(R.id.id_video_totaltime); id_sb_progress = findView(R.id.id_sb_progress); id_btn_video_play = findView(R.id.id_btn_video_play); id_iv_video_play = findView(R.id.id_iv_video_play); id_tv_video_info = findView(R.id.id_tv_video_info); addView(mContainer); } private <T extends View> T findView(int viewId) { return (T) mContainer.findViewById(viewId); } public void setVideoBusiness(VideoBusiness videoBusiness) { this.videoBusiness = videoBusiness; } private void initListener() { //進(jìn)度手勢相關(guān) progressGestureDetector = new GestureDetector(mContext,new ProgressGestureListenr()); progressGestureDetector.setIsLongpressEnabled(true); progressArea.setLongClickable(true); progressArea.setOnTouchListener(this); mMediaController.setOnClickListener(this); id_rl_video_controller.setOnClickListener(this); id_fl_video_play.setOnClickListener(this); id_fl_video_expand.setOnClickListener(this); id_btn_video_play.setOnClickListener(this); id_sb_progress.setOnSeekBarChangeListener(this); } //狀態(tài)切換 public void toggle() { if (isShow) { hideController(); } else { showController(); } } //隱藏底部控制欄 public void hideController() { isShow = false; mMediaController.setVisibility(View.GONE); endTimer(); } //顯示底部控制欄 public void showController() { isShow = true; mMediaController.setVisibility(View.VISIBLE); startTimer(); } private void startTimer() { if (hideHandler != null){ hideHandler.removeMessages(0); } hideHandler.sendEmptyMessageDelayed(0, 5000); } private void endTimer() { hideHandler.removeMessages(0); } public void resetTimer() { endTimer(); startTimer(); } public void showLong() { isShow = true; mMediaController.setVisibility(View.VISIBLE); } //設(shè)置視頻總時間 public void setTotalTime(int time) { String totalTime = getTimeString(time); id_video_totaltime.setText(totalTime); } //設(shè)置視頻當(dāng)前進(jìn)度 public void setProgress(int progress){ int maxProgress = videoBusiness.getTotalTime(); int tempProgress = progress > maxProgress ? maxProgress : progress; id_sb_progress.setProgress(tempProgress); } //是指視頻總進(jìn)度 public void setMaxProgress(int maxProgress){ id_sb_progress.setMax(maxProgress); } //獲取當(dāng)前亮度 private int getCurrentBrightness(){ int currentBrightness = 255; if (brightnessLp.screenBrightness == WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE){ // 獲取系統(tǒng)亮度 try { currentBrightness = Settings.System.getInt(((Activity)mContext).getContentResolver(), Settings.System.SCREEN_BRIGHTNESS); } catch (Settings.SettingNotFoundException e) { e.printStackTrace(); } }else{ // 獲取當(dāng)前窗口亮度 currentBrightness = (int)(brightnessLp.screenBrightness * 255); } return currentBrightness; } @Override public void onClick(View view) { switch (view.getId()){ case R.id.id_ll_controller: //底部控制器 showController(); break; case R.id.id_rl_video_controller: //全屏點(diǎn)擊 toggle(); break; case R.id.id_fl_video_play: // 暫停/播放 case R.id.id_btn_video_play: // 暫停/播放 videoBusiness.playVideo(id_btn_video_play,id_iv_video_play); break; case R.id.id_fl_video_expand: //全屏 resetTimer(); videoBusiness.toggleScreenDir(view); break; } } @Override public boolean onTouch(View view, MotionEvent event) { getParent().requestDisallowInterceptTouchEvent(true); if (event.getAction() == MotionEvent.ACTION_UP) { mProgressIndicator.setVisibility(View.INVISIBLE); if (GESTURE_FLAG == GESTURE_MODIFY_PROGRESS) { //調(diào)節(jié)進(jìn)度 Log.e("進(jìn)度時間","targetTime="+targetTime); videoBusiness.seekToPlay(targetTime); videoBusiness.isSeekBarEnable = true; hideController(); } GESTURE_FLAG = 0;// 手指離開屏幕后,重置調(diào)節(jié)音量或進(jìn)度的標(biāo)志 } return progressGestureDetector.onTouchEvent(event); } private int currentPosition; //當(dāng)前播放進(jìn)度 private int totalPosition; //總播放進(jìn)度 class ProgressGestureListenr implements GestureDetector.OnGestureListener{ private boolean firstScroll = false;// 每次觸摸屏幕后,第一次scroll的標(biāo)志 private int slop;// 觸發(fā)設(shè)置變動的最小距離 @Override public boolean onDown(MotionEvent e) { //用戶按下屏幕就會觸發(fā) //初始數(shù)據(jù) slop = DensityUtil.dp2px(mContext,2); currentPosition = videoBusiness.getCurrentTime(); totalPosition = videoBusiness.getTotalTime(); firstScroll = true; return false; } @Override public void onShowPress(MotionEvent e) { //down事件發(fā)生而move或則up還沒發(fā)生前觸發(fā)該事件 } @Override public boolean onSingleTapUp(MotionEvent e) { //一次點(diǎn)擊up事件 toggle(); if(videoBusiness.isPlaying()){ //正在播放 return false; }else{ //暫?;蛘唛_始播放 videoBusiness.playVideo(id_btn_video_play,id_iv_video_play); isShow = false; return true; } } //在屏幕上拖動事件 @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { if (firstScroll) {// 以觸摸屏幕后第一次滑動為標(biāo)準(zhǔn),避免在屏幕上操作切換混亂 // 橫向的距離變化大則調(diào)整進(jìn)度,縱向的變化大則調(diào)整音量 Log.e("xxxxxxx",e1.getX()+""); Log.e("yyyyyyy",e1.getY()+""); setScroll(e1, distanceX, distanceY); } // 如果每次觸摸屏幕后第一次scroll是調(diào)節(jié)進(jìn)度,那之后的scroll事件都處理音量進(jìn)度,直到離開屏幕執(zhí)行下一次操作 switch (GESTURE_FLAG){ case GESTURE_MODIFY_PROGRESS: //調(diào)節(jié)當(dāng)前進(jìn)度 setCurrentProgress(distanceX, distanceY,slop); break; case GESTURE_MODIFY_VOLUME: //調(diào)節(jié)當(dāng)前音量 setCurrentVolume(distanceX, distanceY,slop); break; case GESTURE_MODIFY_BRIGHTNESS: //調(diào)節(jié)當(dāng)前亮度 setCurrentBrightess(distanceX, distanceY,slop); break; } firstScroll=false; return false; } @Override public void onLongPress(MotionEvent e) { //長按事件 } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { //滑動手勢事件 return false; } } //滑動事件 private void setScroll(MotionEvent e1, float distanceX, float distanceY) { int screenWidth = ScreenUtil.getScreenWidth(mContext); Log.e("屏寬",screenWidth+""); //橫向的距離變化大則調(diào)整進(jìn)度,縱向的變化大則調(diào)整音量 mProgressIndicator.setVisibility(View.VISIBLE); if (Math.abs(distanceX) >= Math.abs(distanceY)) { //調(diào)整進(jìn)度 progressBar.setVisibility(View.INVISIBLE); id_tv_video_info.setVisibility(VISIBLE); GESTURE_FLAG = GESTURE_MODIFY_PROGRESS; videoBusiness.isSeekBarEnable = false; endTimer(); showLong(); }else { //調(diào)整音量 progressBar.setVisibility(VISIBLE); id_tv_video_info.setVisibility(INVISIBLE); if (e1.getX() > screenWidth / 2){ //屏幕右邊上下滑動調(diào)整音量 //右半屏音量 setVideoVolume(); }else{ //屏幕左邊上下滑動調(diào)整亮度 //左半屏亮度 setVideoBrightness(); } } } //設(shè)置當(dāng)前進(jìn)度 private void setCurrentProgress(float distanceX, float distanceY,float slop) { if (Math.abs(distanceX) > Math.abs(distanceY)) {// 橫向移動大于縱向移動 //Log.e("setCurrentProgress",distanceX+""); if(distanceX >= slop){ //從右往左滑 快退 mProgressIndicator.setBackgroundResource(R.drawable.kuaitui); if (currentPosition > 1000) { currentPosition -= 1500; } }else if(distanceX <= -slop){ //從左往右滑 快進(jìn) mProgressIndicator.setBackgroundResource(R.drawable.kuaijin); if (currentPosition < totalPosition) { currentPosition += 1500; } } } targetTime = currentPosition; Log.e("進(jìn)度時間","currentPosition="+currentPosition); id_sb_progress.setProgress(currentPosition); id_video_time.setText(getTimeString(currentPosition)); String videoPbInfo = getTimeString(currentPosition)+"/"+ getTimeString(totalPosition); id_tv_video_info.setText(videoPbInfo); } //設(shè)置當(dāng)前亮度 private void setCurrentBrightess(float distanceX, float distanceY, float slop) { currentBrightness = getCurrentBrightness(); if (Math.abs(distanceY) > Math.abs(distanceX)) {// 縱向移動大于橫向移動 if (distanceY >= slop) {// 上滑 亮度調(diào)大,注意橫屏?xí)r的坐標(biāo)體系,盡管左上角是原點(diǎn),但橫向向上滑動時distanceY為正 if (currentBrightness < maxBrightness) {// 為避免調(diào)節(jié)過快,distanceY應(yīng)大于一個設(shè)定值 currentBrightness += 8; } } else if (distanceY <= -slop) {// 亮度調(diào)小 if (currentBrightness > 0) { currentBrightness -= 8; } if (currentBrightness<0){ currentBrightness=0; } } mProgressIndicator.setBackgroundResource(R.drawable.liangdu); progressBar.setProgress(currentBrightness); changeAppBrightness(mContext,currentBrightness); } } //設(shè)置當(dāng)前音量 private void setCurrentVolume(float distanceX, float distanceY,float slop) { currentVolume = audiomanager.getStreamVolume(AudioManager.STREAM_MUSIC); // 獲取當(dāng)前值 if (Math.abs(distanceY) > Math.abs(distanceX)) { // 縱向移動大于橫向移動 if (distanceY >= slop) { // 上滑 音量調(diào)大,注意橫屏?xí)r的坐標(biāo)體系,盡管左上角是原點(diǎn),但橫向向上滑動時distanceY為正 if (currentVolume < maxVolume) {// 為避免調(diào)節(jié)過快,distanceY應(yīng)大于一個設(shè)定值 currentVolume++; } mProgressIndicator.setBackgroundResource(R.drawable.yinliang); } else if (distanceY <= -slop) {// 音量調(diào)小 下滑 if (currentVolume > 0) { currentVolume--; if (currentVolume == 0) {// 靜音,設(shè)定靜音獨(dú)有的圖片 mProgressIndicator.setBackgroundResource(R.drawable.jingying); } } } progressBar.setProgress(currentVolume); audiomanager.setStreamVolume(AudioManager.STREAM_MUSIC, currentVolume, 0); } } //設(shè)置視頻亮度 private void setVideoBrightness() { progressBar.setMax(maxBrightness); progressBar.setProgress(currentBrightness); mProgressIndicator.setBackgroundResource(R.drawable.liangdu); GESTURE_FLAG = GESTURE_MODIFY_BRIGHTNESS; } //設(shè)置視頻音量 private void setVideoVolume() { progressBar.setMax(maxVolume); progressBar.setProgress(currentVolume); mProgressIndicator.setBackgroundResource(R.drawable.yinliang); GESTURE_FLAG = GESTURE_MODIFY_VOLUME; } //改變系統(tǒng)亮度 public void changeAppBrightness(Context context, int brightness) { Window window = ((Activity) context).getWindow(); WindowManager.LayoutParams lp = window.getAttributes(); if (brightness == -1) { lp.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE; } else { lp.screenBrightness = (brightness <= 0 ? 1 : brightness) / 255f; } window.setAttributes(lp); } public String getTimeString(int second) { int temp = second / 1000; int hh = temp / 3600; SimpleDateFormat sdf; if (0 != hh) { sdf = new SimpleDateFormat("HH:mm:ss"); } else { sdf = new SimpleDateFormat("mm:ss"); } String format = sdf.format(new Date(second)); return format; } //進(jìn)度條改變 @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { String timeString = getTimeString(progress); id_video_time.setText(timeString); } //開始拖動 @Override public void onStartTrackingTouch(SeekBar seekBar) { showLong(); videoBusiness.removeUIMessage(); } //結(jié)束拖動 @Override public void onStopTrackingTouch(SeekBar seekBar) { showController(); int progress = seekBar.getProgress(); videoBusiness.seekToPlay(progress); } }
看完上述內(nèi)容,你們掌握使用VideoView自定義控制面板怎么實(shí)現(xiàn)視頻播放器的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!
本文標(biāo)題:使用VideoView自定義控制面板怎么實(shí)現(xiàn)視頻播放器
URL分享:http://jinyejixie.com/article26/iehijg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動網(wǎng)站建設(shè)、用戶體驗(yàn)、網(wǎng)頁設(shè)計公司、靜態(tài)網(wǎng)站、Google、品牌網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)