可可工作室出品:
欢迎使用可可直播视频播放器:
网上大多数直播软件都会提供一个功能就是自定义,这个由于版本问题,而为了让用户看到自己想看的频道,可以让用户自己添加找到的源,然后进行播放,俗话说法不责众,这个功能是如何实现的呢,其实也是很简单的,无法就是记录下用户添加的数据,然后保存下来,这里主要用到了数据库,用户点击自己添加的源,程序会从数据库取出链接,例如http,rtsp等开头的流媒体链接,具体的实现如下,我们是在之前
首先就是设计一个布局,里面使用ListView来填充,custom.xml,内容如下:
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
android:id="@+id/custom_title"
android:layout_width="match_parent"
android:layout_height="30dp"
android:text="直播"
android:textSize="27sp"
android:gravity="center"
/>
android:id="@+id/custom_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
我们同时还需要一个ListView的一个Item和一个foot用来显示添加的源和实现添加功能,内容如下:
custom_list_item.xml
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
android:id="@+id/custom_list_item_name"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="频道"
/>
android:id="@+id/custom_list_item_url"
android:layout_width="match_parent"
android:layout_height="30dp"
android:text="视频源链接"
/>
custom_list_foot.xml
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
android:layout_width="match_parent"
android:layout_height="30dp"
android:text="点击此处添加视频源"
android:textSize="25sp"
/>
我上面只是使用TextView来显示,如果需要美化,可以添加ImageView来实现图文并茂,布局写完后,我们就要添加一个数据库用来记录添加的视频源,为了方便起见,我们还需要定义一个自定义视频内容格式的类,内容如下:
CustomVideo.java
package com.jwzhangjie.live.type;
import java.io.Serializable;
publ