ExoPlayer google 试用exoplayer:r2.3.0
来源:互联网 发布:oracle sql性能优化 编辑:程序博客网 时间:2024/06/06 07:51
ExoPlayer 2.3效果
HLS 和MP4均测试无问题
代码如下
build.xml
apply plugin: 'com.android.application'android { compileSdkVersion 23 buildToolsVersion "25.0.2" defaultConfig { applicationId "com.example.test_ijk" minSdkVersion 15 targetSdkVersion 23 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }}dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:23.4.0' testCompile 'junit:junit:4.12' compile 'com.google.android.exoplayer:exoplayer:r2.3.0' compile 'com.google.android.exoplayer:exoplayer:r1.5.11'}
layout.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.test_ijk.MainActivity"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="start" android:text="start play" /> <com.google.android.exoplayer2.ui.SimpleExoPlayerView android:id="@+id/simpleExoPlayerView" android:layout_gravity="left|top" android:layout_centerInParent="true" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <View android:layout_width="fill_parent" android:layout_height="fill_parent" android:visibility="gone" class="com.google.android.exoplayer.VideoSurfaceView" android:id="@+id/surfaceView" android:layout_gravity="left|top" android:layout_centerInParent="true" /></RelativeLayout>
package com.example.test_ijk;import android.content.Context;import android.net.Uri;import android.os.Bundle;import android.os.Handler;import android.support.v7.app.AppCompatActivity;import android.view.View;import com.google.android.exoplayer2.DefaultLoadControl;import com.google.android.exoplayer2.ExoPlayerFactory;import com.google.android.exoplayer2.LoadControl;import com.google.android.exoplayer2.SimpleExoPlayer;import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;import com.google.android.exoplayer2.extractor.ExtractorsFactory;import com.google.android.exoplayer2.source.ExtractorMediaSource;import com.google.android.exoplayer2.source.MediaSource;import com.google.android.exoplayer2.source.hls.HlsMediaSource;import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;import com.google.android.exoplayer2.trackselection.TrackSelection;import com.google.android.exoplayer2.trackselection.TrackSelector;import com.google.android.exoplayer2.ui.SimpleExoPlayerView;import com.google.android.exoplayer2.upstream.BandwidthMeter;import com.google.android.exoplayer2.upstream.DataSource;import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;import com.google.android.exoplayer2.util.Util;/** * android google exoplay *///https://google.github.io/ExoPlayer/guide.html#creating-the-player//http://blog.csdn.net/dengpeng_/article/details/54910840public class MainActivity extends AppCompatActivity { String url=""; Context context; TrackSelection.Factory videoTrackSelectionFactory; Handler mainHandler = new Handler(); MediaSource videoSource; SimpleExoPlayer player ; public void start(View v){ } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); context=MainActivity.this; setContentView(R.layout.activity_main); // 1.创建一个默认TrackSelector BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); // 2.创建一个默认的LoadControl LoadControl loadControl = new DefaultLoadControl(); // 3.创建播放器 player = ExoPlayerFactory.newSimpleInstance(context,trackSelector,loadControl); SimpleExoPlayerView simpleExoPlayerView= (SimpleExoPlayerView) findViewById(R.id.simpleExoPlayerView); // 将player关联到View上 simpleExoPlayerView.setPlayer(player); DefaultBandwidthMeter bandwidthMeter2 = new DefaultBandwidthMeter();// Produces DataSource instances through which media data is loaded. DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, Util.getUserAgent(context, "yourApplicationName"), bandwidthMeter2); ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); url="http://mpv.videocc.net/ce0812b122/a/ce0812b122bf0fb49d79ebd97cbe98fa_1.mp4"; // test hls //url="http://hls.videocc.net/ce0812b122/c/ce0812b122c492470605bc47d3388a09_3.m3u8"; if(url.contains(".m3u8")){ videoSource =new HlsMediaSource(Uri.parse(url),dataSourceFactory,null,null); }else{ //test mp4 videoSource = new ExtractorMediaSource(Uri.parse(url), dataSourceFactory, extractorsFactory, null, null); } player.prepare(videoSource);// Prepare the player with the source. } @Override protected void onDestroy() { super.onDestroy(); player.release(); }}
阅读全文
0 0
- ExoPlayer google 试用exoplayer:r2.3.0
- ExoPlayer
- ExoPlayer
- android 视频播放 Google exoplayer
- Google Exoplayer之全面认识
- Google Exoplayer之全面认识
- Exoplayer学习
- ExoPlayer备忘录
- EXOplayer简书
- ExoPlayer 浅析
- ExoPlayer浅析
- ExoPlayer随笔
- ExoPlayer用户手册
- 使用google开源框架Exoplayer开发自定义播放器
- 使用google开源框架Exoplayer开发自定义播放器
- ExoPlayer类说明
- ExoPlayer (待修订)
- ExoPlayer 开发者指导
- 需要求3个长方体的体积,写一个基于对象的程序,数据成员包括 length width height 要求用成员函数实现以下功能
- EM算法在高斯混合模型中的应用
- 从零开始学算法(六)最短路径之Dijkstra算法
- 火影歌单
- HTTP 传输内容的压缩
- ExoPlayer google 试用exoplayer:r2.3.0
- 从一个git仓库迁移到另外一个git仓库
- BZOJ 1798 [Ahoi2009] Seq 维护序列seq [线段树+多重标记下传]【数据结构】
- 基于等高线算法绘制几何管道,并显示数据
- leetcode 111. Minimum Depth of Binary Tree(week 15)
- 【iTween】单点移动和旋转
- java.lang.ClassNotFoundException: com.mysql.jdbc.Driver 解决方法
- UESTC 1593 老司机破阵 优先队列+双端链表
- 对JavaScript中对象字面量的理解