视频广告播放器(缓存、循环播放)

视频广告播放器特点:1、网络视频缓存处理;2、循环播放功能;3、动态更新视频广告

一、采用AndroidVideoCache进行网络视频的缓存处理(框架地址https://github.com/danikula/AndroidVideoCache)

1、添加依赖 compile 'com.danikula:videocache:2.7.0'

2、创建缓存代理

        HttpProxyCacheServer proxy = new HttpProxyCacheServer.Builder(this)
                                                             .maxCacheSize(1024 * 1024 * 1024) //1Gb缓存
                                                             .maxCacheFilesCount(5)//最大缓存5个视频
                                                             .build();

3、获取视频缓存文件路径

String videoPath= proxy.getProxyUrl(url);

二、VideoView实现循环播放功能

public void playVideo(){
        index = index % urlList.size();
        String proxyUrl = proxy.getProxyUrl(urlList.get(index));
        videoView.setVideoPath(proxyUrl);
        videoView.start();
        videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mPlayer) {
                index ++;
                playVideo();//递归
            }
        });
    }

三、动态更新广告

可以通过集成第三方推送实现(接收到推送消息,重新网络请求视频广告列表即可),在这里就不再写具体实现了

四、项目下载地址

http://download.csdn.net/download/yufumatou/10210308

猜你喜欢

转载自blog.csdn.net/yufumatou/article/details/79086662