Android使用SurfaceView播放视频 简单介绍

本文介绍了如何在Android应用中使用SurfaceView来播放视频,相较于VideoView,SurfaceView提供了更灵活的控制。首先展示SurfaceView的使用代码,然后在Activity中实现SurfaceHolder.Callback接口来操作视频播放。虽然这种方式需要更多的自定义工作,但能更好地进行视频显示的定制。
摘要由CSDN通过智能技术生成

Android中播放视频,简单就直接用VideoView,这是系统集成的一个视频播放组件,使用起来还是比较方便的。

这里要写的是使用SurfaceView播放视频,SurfaceView的方便之处我不再多说,具体使用方法如下。

直接上代码:

布局文件长这样:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_black">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true">

        <SurfaceView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/video_surfaceview"
            android:layout_centerInParent="true">
        </SurfaceView>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/layout_loading"
            android:gravity="center"
            android:visibility="visible"
            android:layout_centerInParent="true">

            <ProgressBar
                style="?android:attr/progressBarStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/progressBar3" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="正在加载..."
                android:id="@+id/tv_loading"
                android:textColor="@color/color_white"
                android:layout_marginLeft="5dp" />

        </LinearLayout>
    </RelativeLayout>

    <LinearLayout
       
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值