Android开发 MediaPlayer播放本地视频完善的demo(只是代码记录)

本文提供了一个完整的Android使用MediaPlayer播放本地视频的Demo,详细解析了相关代码实现,适合Android开发者参考学习。

xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/root_layout"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:keepScreenOn="true"
    android:background="@color/colorBlack1"
    tools:context=".work.share.VideoPlayActivity">

    <SurfaceView
        android:id="@+id/video_play_surfaceview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintVertical_bias="0.5"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"/>

    <ImageView
        android:id="@+id/start_and_stop"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="https://blog.csdn.net/@mipmap/ic_sex_male"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@id/vedio_current_time"
        app:layout_constraintBottom_toBottomOf="parent" />

    <TextView
        android:id="@+id/vedio_current_time"
        android:text="当前时间"
        android:textColor="@color/fontWhite"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        app:layout_constraintTop_toTopOf="@id/start_and_stop"
        app:layout_constraintBottom_toBottomOf="@id/start_and_stop"
        app:layout_constraintLeft_toRightOf="@id/start_and_stop"
        app:layout_constraintRight_toLeftOf="@id/vedio_seek"/>

   <SeekBar
       android:id="@+id/vedio_seek"
       android:layout_width="0dp"
       android:layout_height="0dp"
       android:maxHeight="3dp"
       android:minHeight="3dp"
       android:progressDrawable="@drawable/vedio_seekbar_bg"
       app:layout_constraintTop_toTopOf="@id/start_and_stop"
       app:layout_constraintBottom_toBottomOf="@id/start_and_stop"
       app:layout_constraintLeft_toRightOf="@id/vedio_current_time"
       app:layout_constraintRight_toRightOf="@id/vedio_total_time"/>

    <TextView
        android:id="@+id/vedio_total_time"
        android:textColor="@color/fontWhite"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="10dp"
        app:layout_constraintTop_toTopOf="@id/start_and_stop"
        app:layout_constraintBottom_toBottomOf="@id/start_and_stop"
        app:layout_constraintLeft_toRightOf="@id/vedio_seek"
        app:layout_constraintR
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值