Android中使用自定义的VideoController和MediaPlayer实现视频的窗口和全屏播放

来源:互联网 发布:国税发票打印软件 编辑:程序博客网 时间:2024/06/03 13:21

基于MediaPlayer的能窗口和全屏切换的视屏播放器

之前在一个项目中做了一个能窗口化和全屏切换的播放器,做之前在网上也看了很多的demo,今天为了记录下自己的学习成果,特意将它写下来供自己以后参考和对大家有所帮助,废话不多说,直接开始正题。

一:视频播放的Activity类

首先我们看视频播放的Activity的代码之前,我们先看一下google文档中对mediaPlayer的生命周期的描述的图:

mediaPlayer对象的整个生命周期是从通过new的方式创建或则reset()方法初始化(这个期间mediaPlayer处于idel状态)一直到release()方法调用,这其中两种初始化的方式有一定的区别,如果我们通过new的方式创建mediaplayer对象后,我们立即调用getCurrentPostion(),getDuration(), getVideoHeight()...等等方法后程序会出错,在
onErrorListener()不会被调用,而通过reset()创建的话就不会出现类似的情况,还有记得一点就是当我们的mediaPlayer对象不在需要的时候记得将其释放掉,通过调用release()方法。
从图中的红箭头标注可以看出我们初始化mediaPlayer的时候可以有两种方式prepare()和prepareAsync();这两者从文档中看出有些许的不同,前者prepare()当我们播放的视屏是一个本地的file文件的时候调用,他会当加载到可以播放时才进行播放,而后者针对于在线的流文件。

大致的了解了MediaPlayer后,我们就看下项目中的代码:

    public class VideoPlayerActivity extends Activity implements SurfaceHolder.Callback, MediaPlayer.OnPreparedListener, VideoControllerView.MediaPlayerControl, View.OnClickListener {                SurfaceView videoSurface;          MediaPlayer player;          VideoControllerView controller;//这里的VideoControllerView是我们自己定义的,在下面会给大家贴出代码          private boolean isFullScrenen;          private Display currDisplay;          private int position;          private FrameLayout videoSurfaceContainer;//用于包裹SurfaceView的,通过改变其的params来切换窗口模式和全屏模式          private int size = 1;                @Override          protected void onCreate(Bundle savedInstanceState) {              super.onCreate(savedInstanceState);              setContentView(R.layout.activity_video_player);                    currDisplay = this.getWindowManager().getDefaultDisplay();              String videoPath = getIntent().getStringExtra("videoPath");//通过intent获取传递过来的视屏资源的地址(可以是本地的文件或则一个url)              videoSurface = (SurfaceView) findViewById(R.id.videoSurface);              videoSurfaceContainer = (FrameLayout) findViewById(R.id.videoSurfaceContainer);              videoSurfaceContainer.setOnClickListener(this);//设置包裹容器的点击事件,主要用于底部控制栏的隐藏和现实,如果一段时间不点击也会自动消失              SurfaceHolder videoHolder = videoSurface.getHolder();                    videoHolder.addCallback(this);//创建SufaceView的监听事件                    player = new MediaPlayer();//初始化MediaPlayer              controller = new VideoControllerView(this);//初始化底部控制栏                    try {                  player.reset();                  player.setAudioStreamType(AudioManager.STREAM_MUSIC);//设置类型参数                  player.setDataSource(this, Uri.parse(videoPath));//设置视频的地址                  player.setOnPreparedListener(this);              } catch (IllegalArgumentException e) {                  e.printStackTrace();              } catch (SecurityException e) {                  e.printStackTrace();              } catch (IllegalStateException e) {                  e.printStackTrace();              } catch (IOException e) {                  e.printStackTrace();              }          }                      // Implement SurfaceHolder.Callback          @Override          public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {                }                @Override          public void surfaceCreated(SurfaceHolder holder) {              player.setDisplay(holder);//为MediaPlayer设置播放的区域              player.prepareAsync();//准备播放          }                @Override          public void surfaceDestroyed(SurfaceHolder holder) {                }                @Override          public void onConfigurationChanged(Configuration newConfig) {//该方法回掉是在横竖屏切换的时候调用的,在这个方法当中我们需要对视屏              super.onConfigurationChanged(newConfig);//我们知道在视频横竖屏切换的时候页面会重新加载,这不是我们想要的,所以我们别忘了              initStartPlayer();//在manifest文件中对Activity进行配置// configChanges="keyboardHidden|orientation|screenSize" } //切换时保存当前视频播放进度 @Override protected void onSaveInstanceState(Bundle outState) {//当横竖屏切换的时候我们记住上次播放的位置参数 super.onSaveInstanceState(outState); int position = player.getCurrentPosition(); outState.putInt("position", position); } //重新获取视频播放进度 @Override protected void onRestoreInstanceState(Bundle savedInstanceState) {//读取播放的位置 super.onRestoreInstanceState(savedInstanceState); position = savedInstanceState.getInt("position"); if (position != 0) { player.seekTo(position); } }  @Override public void onPrepared(MediaPlayer mp) { initStartPlayer(); } private void initStartPlayer() {//这个方法就是对视屏窗口的大小进行设置了 int vWidth = player.getVideoWidth();int vHeight = player.getVideoHeight(); DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); int windowWidth = dm.widthPixels; int windowHeight = dm.heightPixels; //如果video的宽或者高超出了当前屏幕的大小,则要进行缩 float wRatio = (float) vWidth / (float) currDisplay.getWidth(); float hRatio = (float) vHeight / (float) currDisplay.getHeight(); //选择大的一个进行缩放 float ratio = Math.max(wRatio, hRatio); vWidth = (int) Math.ceil((float) vWidth / ratio);vHeight = (int) Math.ceil((float) vHeight / ratio); //设置surfaceView的布局参数 FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(vWidth, vHeight);lp.setMargins((windowWidth - vWidth) / 2, 0, 0, 0); videoSurface.setLayoutParams(lp);controller.setMediaPlayer(this);//为VideoController设置MediaPlayer controller.setAnchorView((FrameLayout) findViewById(R.id.videoSurfaceContainer)); controller.show(); } // End MediaPlayer.OnPreparedListener // Implement VideoMediaController.MediaPlayerControl@Override public boolean canPause() { return true; } @Override public boolean canSeekBackward() { return true; } @Overridepublic boolean canSeekForward() { return true; } @Override public int getBufferPercentage() { return 0; } @Override public int getCurrentPosition() { return player.getCurrentPosition(); } @Override public int getDuration() { return player.getDuration(); } @Override public boolean isPlaying() { return player.isPlaying(); } @Override public void pause() { player.pause(); } @Override public void seekTo(int i) { player.seekTo(i); } @Override public void start() { player.start(); } @Override public boolean isFullScreen() { int orientation = this.getRequestedOrientation(); isFullScrenen = (orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); return isFullScrenen; } @Override public void toggleFullScreen() { //通过手动的方式改变屏幕的方向 if (isFullScrenen) {setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } // End VideoMediaController.MediaPlayerControl @Override protected void onDestroy() { super.onDestroy(); if (player != null) { if (player.isPlaying()) { player.stop(); player.release(); //释放MediaPlayer } } }@Override public void onClick(View v) {//控制底部控制条的显示和隐藏 switch (v.getId()){case R.id.videoSurfaceContainer: if (size % 2 == 1){ controller.show(); }else { controller.hide(); } size++; break; }}} 


上面的代码有点乱,大家见谅,下面为大家贴出的是布局文件,这个就更加的简单了:

二:现在为大家讲下底部控制条

这部分的代码是我在stackflow上copy下来的,然后自己改了一小点,就直接给大家上代码吧
public class VideoControllerView extends FrameLayout {    private static final String TAG = "VideoControllerView";    private MediaPlayerControl mPlayer;    private Context mContext;    private ViewGroup mAnchor;    private View mRoot;    private ProgressBar mProgress;    private TextView mEndTime, mCurrentTime;    private boolean mShowing;    private boolean mDragging;    private static final int sDefaultTimeout = 3000;    private static final int FADE_OUT = 1;    private static final int SHOW_PROGRESS = 2;    private boolean mUseFastForward;    private boolean mFromXml;    private boolean mListenersSet;    private OnClickListener mNextListener, mPrevListener;    StringBuilder mFormatBuilder;    Formatter mFormatter;    private ImageButton mPauseButton;    private ImageButton mFfwdButton;    private ImageButton mRewButton;    private ImageButton mNextButton;    private ImageButton mPrevButton;    private ImageButton mFullscreenButton;    private Handler mHandler = new MessageHandler(this);    public VideoControllerView(Context context, AttributeSet attrs) {        super(context, attrs);        mRoot = null;        mContext = context;        mUseFastForward = true;        mFromXml = true;        Log.i(TAG, TAG);    }    public VideoControllerView(Context context, boolean useFastForward) {        super(context);        mContext = context;        mUseFastForward = useFastForward;        Log.i(TAG, TAG);    }    public VideoControllerView(Context context) {        this(context, true);        Log.i(TAG, TAG);    }    @Override    public void onFinishInflate() {        if (mRoot != null)            initControllerView(mRoot);    }    public void setMediaPlayer(MediaPlayerControl player) {        mPlayer = player;        updatePausePlay();        updateFullScreen();    }    /**     * Set the view that acts as the anchor for the control view.     * This can for example be a VideoView, or your Activity's main view.     *     * @param view The view to which to anchor the controller when it is visible.     */    public void setAnchorView(ViewGroup view) {        mAnchor = view;        LayoutParams frameParams = new LayoutParams(                ViewGroup.LayoutParams.MATCH_PARENT,                ViewGroup.LayoutParams.MATCH_PARENT        );        removeAllViews();        View v = makeControllerView();        addView(v, frameParams);    }    /**     * Create the view that holds the widgets that control playback.     * Derived classes can override this to create their own.     *     * @return The controller view.     * @hide This doesn't work as advertised     */    protected View makeControllerView() {        LayoutInflater inflate = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);        mRoot = inflate.inflate(R.layout.media_controller, null);        initControllerView(mRoot);        return mRoot;    }    private void initControllerView(View v) {        mPauseButton = (ImageButton) v.findViewById(R.id.pause);        if (mPauseButton != null) {            mPauseButton.requestFocus();            mPauseButton.setOnClickListener(mPauseListener);        }        mFullscreenButton = (ImageButton) v.findViewById(R.id.fullscreen);        if (mFullscreenButton != null) {            mFullscreenButton.requestFocus();            mFullscreenButton.setOnClickListener(mFullscreenListener);        }        mFfwdButton = (ImageButton) v.findViewById(R.id.ffwd);        if (mFfwdButton != null) {            mFfwdButton.setOnClickListener(mFfwdListener);            if (!mFromXml) {                mFfwdButton.setVisibility(mUseFastForward ? View.VISIBLE : View.GONE);            }        }        mRewButton = (ImageButton) v.findViewById(R.id.rew);        if (mRewButton != null) {            mRewButton.setOnClickListener(mRewListener);            if (!mFromXml) {                mRewButton.setVisibility(mUseFastForward ? View.VISIBLE : View.GONE);            }        }        // By default these are hidden. They will be enabled when setPrevNextListeners() is called         mNextButton = (ImageButton) v.findViewById(R.id.next);        if (mNextButton != null && !mFromXml && !mListenersSet) {            mNextButton.setVisibility(View.GONE);        }        mPrevButton = (ImageButton) v.findViewById(R.id.prev);        if (mPrevButton != null && !mFromXml && !mListenersSet) {            mPrevButton.setVisibility(View.GONE);        }        mProgress = (SeekBar) v.findViewById(R.id.mediacontroller_progress);        if (mProgress != null) {            if (mProgress instanceof SeekBar) {                SeekBar seeker = (SeekBar) mProgress;                seeker.setOnSeekBarChangeListener(mSeekListener);            }            mProgress.setMax(1000);        }        mEndTime = (TextView) v.findViewById(R.id.time);        mCurrentTime = (TextView) v.findViewById(R.id.time_current);        mFormatBuilder = new StringBuilder();        mFormatter = new Formatter(mFormatBuilder, Locale.getDefault());        installPrevNextListeners();    }    /**     * Show the controller on screen. It will go away     * automatically after 3 seconds of inactivity.     */    public void show() {        show(sDefaultTimeout);    }    /**     * Disable pause or seek buttons if the stream cannot be paused or seeked.     * This requires the control interface to be a MediaPlayerControlExt     */    private void disableUnsupportedButtons() {        if (mPlayer == null) {            return;        }        try {            if (mPauseButton != null && !mPlayer.canPause()) {                mPauseButton.setEnabled(false);            }            if (mRewButton != null && !mPlayer.canSeekBackward()) {                mRewButton.setEnabled(false);            }            if (mFfwdButton != null && !mPlayer.canSeekForward()) {                mFfwdButton.setEnabled(false);            }        } catch (IncompatibleClassChangeError ex) {            // We were given an old version of the interface, that doesn't have            // the canPause/canSeekXYZ methods. This is OK, it just means we            // assume the media can be paused and seeked, and so we don't disable            // the buttons.        }    }    /**     * Show the controller on screen. It will go away     * automatically after 'timeout' milliseconds of inactivity.     *     * @param timeout The timeout in milliseconds. Use 0 to show     *                the controller until hide() is called.     */    public void show(int timeout) {        if (!mShowing && mAnchor != null) {            setProgress();            if (mPauseButton != null) {                mPauseButton.requestFocus();            }            disableUnsupportedButtons();            LayoutParams tlp = new LayoutParams(                    ViewGroup.LayoutParams.MATCH_PARENT,                    ViewGroup.LayoutParams.WRAP_CONTENT,                    Gravity.BOTTOM            );            mAnchor.addView(this, tlp);            mShowing = true;        }        updatePausePlay();        updateFullScreen();        // cause the progress bar to be updated even if mShowing        // was already true.  This happens, for example, if we're        // paused with the progress bar showing the user hits play.        mHandler.sendEmptyMessage(SHOW_PROGRESS);        Message msg = mHandler.obtainMessage(FADE_OUT);        if (timeout != 0) {            mHandler.removeMessages(FADE_OUT);            mHandler.sendMessageDelayed(msg, timeout);        }    }    public boolean isShowing() {        return mShowing;    }    /**     * Remove the controller from the screen.     */    public void hide() {        if (mAnchor == null) {            return;        }        try {            mAnchor.removeView(this);            mHandler.removeMessages(SHOW_PROGRESS);        } catch (IllegalArgumentException ex) {            Log.w("MediaController", "already removed");        }        mShowing = false;    }    private String stringForTime(int timeMs) {        int totalSeconds = timeMs / 1000;        int seconds = totalSeconds % 60;        int minutes = (totalSeconds / 60) % 60;        int hours = totalSeconds / 3600;        mFormatBuilder.setLength(0);        if (hours > 0) {            return mFormatter.format("%d:%02d:%02d", hours, minutes, seconds).toString();        } else {            return mFormatter.format("%02d:%02d", minutes, seconds).toString();        }    }    private int setProgress() {        if (mPlayer == null || mDragging) {            return 0;        }        int position = mPlayer.getCurrentPosition();        int duration = mPlayer.getDuration();        if (mProgress != null) {            if (duration > 0) {                // use long to avoid overflow                long pos = 1000L * position / duration;                mProgress.setProgress((int) pos);            }            int percent = mPlayer.getBufferPercentage();            mProgress.setSecondaryProgress(percent * 10);        }        if (mEndTime != null)            mEndTime.setText(stringForTime(duration));        if (mCurrentTime != null)            mCurrentTime.setText(stringForTime(position));        return position;    }    private int size;    @Override    public boolean onTouchEvent(MotionEvent event) {        show(sDefaultTimeout);        return true;    }    @Override    public boolean onTrackballEvent(MotionEvent ev) {        show(sDefaultTimeout);        return false;    }    @Override    public boolean dispatchKeyEvent(KeyEvent event) {        if (mPlayer == null) {            return true;        }        int keyCode = event.getKeyCode();        final boolean uniqueDown = event.getRepeatCount() == 0                && event.getAction() == KeyEvent.ACTION_DOWN;        if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK                || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE                || keyCode == KeyEvent.KEYCODE_SPACE) {            if (uniqueDown) {                doPauseResume();                show(sDefaultTimeout);                if (mPauseButton != null) {                    mPauseButton.requestFocus();                }            }            return true;        } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) {            if (uniqueDown && !mPlayer.isPlaying()) {                mPlayer.start();                updatePausePlay();                show(sDefaultTimeout);            }            return true;        } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP                || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) {            if (uniqueDown && mPlayer.isPlaying()) {                mPlayer.pause();                updatePausePlay();                show(sDefaultTimeout);            }            return true;        } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN                || keyCode == KeyEvent.KEYCODE_VOLUME_UP                || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {            // don't show the controls for volume adjustment            return super.dispatchKeyEvent(event);        } else if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU) {            if (uniqueDown) {                hide();            }            return true;        }        show(sDefaultTimeout);        return super.dispatchKeyEvent(event);    }    private OnClickListener mPauseListener = new OnClickListener() {        public void onClick(View v) {            doPauseResume();            show(sDefaultTimeout);        }    };    private OnClickListener mFullscreenListener = new OnClickListener() {        public void onClick(View v) {            doToggleFullscreen();            show(sDefaultTimeout);        }    };    public void updatePausePlay() {        if (mRoot == null || mPauseButton == null || mPlayer == null) {            return;        }        if (mPlayer.isPlaying()) {            mPauseButton.setImageResource(R.mipmap.ic_videopause1_n);        } else {            mPauseButton.setImageResource(R.mipmap.ic_videoplay1_n);        }    }    public void updateFullScreen() {        if (mRoot == null || mFullscreenButton == null || mPlayer == null) {            return;        }        if (mPlayer.isFullScreen()) {            mFullscreenButton.setImageResource(R.drawable.selector_video_full);        }//        else {//            mFullscreenButton.setImageResource(R.mipmap.ic_test_preview_n);//        }    }    private void doPauseResume() {        if (mPlayer == null) {            return;        }        if (mPlayer.isPlaying()) {            mPlayer.pause();        } else {            mPlayer.start();        }        updatePausePlay();    }    private void doToggleFullscreen() {        if (mPlayer == null) {            return;        }        mPlayer.toggleFullScreen();    }    // There are two scenarios that can trigger the seekbar listener to trigger:    //    // The first is the user using the touchpad to adjust the posititon of the    // seekbar's thumb. In this case onStartTrackingTouch is called followed by    // a number of onProgressChanged notifications, concluded by onStopTrackingTouch.    // We're setting the field "mDragging" to true for the duration of the dragging    // session to avoid jumps in the position in case of ongoing playback.    //    // The second scenario involves the user operating the scroll ball, in this    // case there WON'T BE onStartTrackingTouch/onStopTrackingTouch notifications,    // we will simply apply the updated position without suspending regular updates.    private OnSeekBarChangeListener mSeekListener = new OnSeekBarChangeListener() {        public void onStartTrackingTouch(SeekBar bar) {            show(3600000);            mDragging = true;            // By removing these pending progress messages we make sure            // that a) we won't update the progress while the user adjusts            // the seekbar and b) once the user is done dragging the thumb            // we will post one of these messages to the queue again and            // this ensures that there will be exactly one message queued up.            mHandler.removeMessages(SHOW_PROGRESS);        }        public void onProgressChanged(SeekBar bar, int progress, boolean fromuser) {            if (mPlayer == null) {                return;            }            if (!fromuser) {                // We're not interested in programmatically generated changes to                // the progress bar's position.                return;            }            long duration = mPlayer.getDuration();            long newposition = (duration * progress) / 1000L;            mPlayer.seekTo((int) newposition);            if (mCurrentTime != null)                mCurrentTime.setText(stringForTime((int) newposition));        }        public void onStopTrackingTouch(SeekBar bar) {            mDragging = false;            setProgress();            updatePausePlay();            show(sDefaultTimeout);            // Ensure that progress is properly updated in the future,            // the call to show() does not guarantee this because it is a            // no-op if we are already showing.            mHandler.sendEmptyMessage(SHOW_PROGRESS);        }    };    @Override    public void setEnabled(boolean enabled) {        if (mPauseButton != null) {            mPauseButton.setEnabled(enabled);        }        if (mFfwdButton != null) {            mFfwdButton.setEnabled(enabled);        }        if (mRewButton != null) {            mRewButton.setEnabled(enabled);        }        if (mNextButton != null) {            mNextButton.setEnabled(enabled && mNextListener != null);        }        if (mPrevButton != null) {            mPrevButton.setEnabled(enabled && mPrevListener != null);        }        if (mProgress != null) {            mProgress.setEnabled(enabled);        }        disableUnsupportedButtons();        super.setEnabled(enabled);    }    private OnClickListener mRewListener = new OnClickListener() {        public void onClick(View v) {            if (mPlayer == null) {                return;            }            int pos = mPlayer.getCurrentPosition();            pos -= 5000; // milliseconds            mPlayer.seekTo(pos);            setProgress();            show(sDefaultTimeout);        }    };    private OnClickListener mFfwdListener = new OnClickListener() {        public void onClick(View v) {            if (mPlayer == null) {                return;            }            int pos = mPlayer.getCurrentPosition();            pos += 15000; // milliseconds            mPlayer.seekTo(pos);            setProgress();            show(sDefaultTimeout);        }    };    private void installPrevNextListeners() {        if (mNextButton != null) {            mNextButton.setOnClickListener(mNextListener);            mNextButton.setEnabled(mNextListener != null);        }        if (mPrevButton != null) {            mPrevButton.setOnClickListener(mPrevListener);            mPrevButton.setEnabled(mPrevListener != null);        }    }    public void setPrevNextListeners(OnClickListener next, OnClickListener prev) {        mNextListener = next;        mPrevListener = prev;        mListenersSet = true;        if (mRoot != null) {            installPrevNextListeners();            if (mNextButton != null && !mFromXml) {                mNextButton.setVisibility(View.VISIBLE);            }            if (mPrevButton != null && !mFromXml) {                mPrevButton.setVisibility(View.VISIBLE);            }        }    }    public interface MediaPlayerControl {        void start();        void pause();        int getDuration();        int getCurrentPosition();        void seekTo(int pos);        boolean isPlaying();        int getBufferPercentage();        boolean canPause();        boolean canSeekBackward();        boolean canSeekForward();        boolean isFullScreen();        void toggleFullScreen();    }    private static class MessageHandler extends Handler {        private final WeakReference<VideoControllerView> mView;        MessageHandler(VideoControllerView view) {            mView = new WeakReference<VideoControllerView>(view);        }        @Override        public void handleMessage(Message msg) {            VideoControllerView view = mView.get();            if (view == null || view.mPlayer == null) {                return;            }            int pos;            switch (msg.what) {                case FADE_OUT:                    view.hide();                    break;                case SHOW_PROGRESS:                    pos = view.setProgress();                    if (!view.mDragging && view.mShowing && view.mPlayer.isPlaying()) {                        msg = obtainMessage(SHOW_PROGRESS);                        sendMessageDelayed(msg, 1000 - (pos % 1000));                    }                    break;            }        }    }}
接下来就是控制条的布局文件了:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"              android:layout_width="match_parent"              android:layout_height="wrap_content"              android:background="#CC000000"              android:orientation="vertical">    <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:gravity="center"            android:orientation="horizontal"            android:paddingTop="4dip">        <ImageButton                android:id="@+id/prev"                style="@android:style/MediaButton.Previous"/>        <ImageButton                android:id="@+id/rew"                style="@android:style/MediaButton.Rew"/>        <ImageButton                android:id="@+id/pause"                style="@android:style/MediaButton.Play"/>        <ImageButton                android:id="@+id/ffwd"                style="@android:style/MediaButton.Ffwd"/>        <ImageButton                android:id="@+id/next"                style="@android:style/MediaButton.Next"/>    </LinearLayout>    <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:orientation="horizontal">        <TextView                android:id="@+id/time_current"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_gravity="center_horizontal"                android:paddingLeft="4dip"                android:paddingRight="4dip"                android:paddingTop="4dip"                android:textColor="@color/material_white"                android:textSize="14sp"                android:textStyle="bold"/>        <SeekBar                android:id="@+id/mediacontroller_progress"                style="?android:attr/progressBarStyleHorizontal"                android:layout_width="0dip"                android:layout_height="32dip"                android:layout_weight="1"/>        <TextView                android:id="@+id/time"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_gravity="center_horizontal"                android:paddingLeft="4dip"                android:paddingRight="4dip"                android:paddingTop="4dip"                android:textColor="@color/material_white"                android:textSize="14sp"                android:textStyle="bold"/>        <ImageButton                android:id="@+id/fullscreen"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_gravity="top"                android:layout_marginTop="1dp"                android:background="@android:color/transparent"                android:paddingBottom="4dip"                android:paddingLeft="10dip"                android:paddingRight="4dip"                android:paddingTop="4dip"                android:src="@drawable/selector_video_full"/>    </LinearLayout></LinearLayout>

好了,就写到这里把,最后提醒一句,如果需要看在线资源的话,记得加上网络权限,由于本人能力有限,文中有错误的地方希望大家多多包涵,谢谢大家!


1 0
原创粉丝点击