Commit 220ed6a089974bfc5ba1bbbd0db84f1fe827217b

Authored by 谷俊
1 parent 8276b1ee

添加切换码率的demo和修改对应文档

app/libs/libcnliveutil.jar
No preview for this file type
app/libs/libcnlivevideo.jar
No preview for this file type
app/src/main/AndroidManifest.xml
... ... @@ -56,6 +56,11 @@
56 56 android:screenOrientation="portrait" />
57 57  
58 58 <activity
  59 + android:name=".SwitchVideoActivity"
  60 + android:configChanges="keyboardHidden|screenSize|orientation"
  61 + android:screenOrientation="portrait" />
  62 +
  63 + <activity
59 64 android:name=".JumpSwitchVideoActivity"
60 65 android:configChanges="keyboardHidden|screenSize|orientation"
61 66 android:screenOrientation="portrait" />
... ...
app/src/main/java/com/cnlive/demo/video/JumpSwitchVideoActivity.java
... ... @@ -27,6 +27,9 @@ public class JumpSwitchVideoActivity extends AppCompatActivity{
27 27 startActivity(new Intent(this,SwitchVideoByIdActivity.class));
28 28 }
29 29  
  30 + public void clickToRateDemo(View view){
  31 + startActivity(new Intent(this,SwitchVideoActivity.class));
  32 + }
30 33  
31 34 }
32 35  
... ...
app/src/main/java/com/cnlive/demo/video/SwitchVideoActivity.java 0 → 100644
  1 +package com.cnlive.demo.video;
  2 +
  3 +import android.os.Bundle;
  4 +import android.support.annotation.Nullable;
  5 +import android.support.v7.app.AppCompatActivity;
  6 +import android.view.View;
  7 +import android.widget.Button;
  8 +import android.widget.ProgressBar;
  9 +import android.widget.Toast;
  10 +
  11 +import com.cnlive.demo.video.model.DataSource;
  12 +import com.cnlive.libs.util.Config;
  13 +import com.cnlive.libs.video.video.SwitchVideoView;
  14 +import com.cnlive.libs.video.video.base.IMediaPlayer;
  15 +import com.cnlive.libs.video.video.base.ISwitchVideoView;
  16 +
  17 +import java.util.ArrayList;
  18 +import java.util.List;
  19 +
  20 +/**
  21 + * Created by gujun on 2017/6/21.
  22 + * 此页面是当点击切换按钮时才进行切换,适用切换视频码率
  23 + * 以四个码率为例,具体几个码率看后台给当前视频配置了几个
  24 + */
  25 +
  26 +public class SwitchVideoActivity extends AppCompatActivity implements IMediaPlayer.OnPreparedListener,
  27 + IMediaPlayer.OnCompletionListener, IMediaPlayer.OnErrorListener, IMediaPlayer.OnInfoListener,
  28 + IMediaPlayer.OnPlayStateListener, IMediaPlayer.OnSeekCompleteListener,
  29 + ISwitchVideoView.OnSwitchVideoPreparedListener, ISwitchVideoView.OnSwitchVideoErrorListener, ISwitchVideoView.OnSwitchVideoCompleteListener {
  30 +
  31 + private SwitchVideoView videoView;
  32 +
  33 + private ProgressBar loading;
  34 + private Button rateL, rateM, rateH, rateHH;
  35 + private List<Button> rateViews;
  36 + //当前播放的视频码率
  37 + private Button curRate;
  38 + //需要切换的视频码率
  39 + private Button switchRate;
  40 +
  41 + @Override
  42 + protected void onCreate(@Nullable Bundle savedInstanceState) {
  43 + super.onCreate(savedInstanceState);
  44 + setContentView(R.layout.activity_switch_video);
  45 + initView();
  46 + initPlay();
  47 + startPlay();
  48 + }
  49 +
  50 + private void initView() {
  51 + rateViews = new ArrayList<>();
  52 + loading = (ProgressBar) findViewById(R.id.loading);
  53 + rateL = (Button) findViewById(R.id.rateL);
  54 + rateM = (Button) findViewById(R.id.rateM);
  55 + rateH = (Button) findViewById(R.id.rateH);
  56 + rateHH = (Button) findViewById(R.id.rateHH);
  57 + rateViews.add(rateL);
  58 + rateViews.add(rateM);
  59 + rateViews.add(rateH);
  60 + rateViews.add(rateHH);
  61 + //默认设置标清
  62 + setSelectRate(rateM);
  63 + }
  64 +
  65 + private void initPlay() {
  66 + videoView = (SwitchVideoView) findViewById(R.id.videoview);
  67 + //认证APP播放权限(使用视讯中国资源)
  68 + videoView.setOnPreparedListener(this);
  69 + videoView.setOnCompletionListener(this);
  70 + videoView.setOnPlayStateListener(this);
  71 + videoView.setOnErrorListener(this);
  72 + videoView.setOnInfoListener(this);
  73 + videoView.setOnSeekCompleteListener(this);
  74 + videoView.setOnSwitchVideoPreparedListener(this);
  75 + videoView.setOnSwitchVideoErrorListener(this);
  76 + videoView.setOnSwitchVideoCompleteListener(this);
  77 + videoView.setKeepScreenOn(true);
  78 + }
  79 +
  80 + private void startPlay() {
  81 + loading.setVisibility(View.VISIBLE);
  82 + curRate = rateM;
  83 +// videoView.setDataSource(new DataSource("82_xinyingshi", Config.TYPE_LIVE, Config.TYPE_PLAY_RATE_2));
  84 + videoView.setDataSource(new DataSource("82_58ff2c30f4714a04a77f854f50d86e3a", Config.TYPE_VOD, Config.TYPE_PLAY_RATE_2));
  85 + }
  86 +
  87 + private void setSelectRate(Button view) {
  88 + for (int i = 0; i < rateViews.size(); i++) {
  89 + rateViews.get(i).setTextColor(rateViews.get(i).getId() == view.getId() ? getResources().getColor(R.color.colorRateSel) : getResources().getColor(R.color.colorRateNor));
  90 + }
  91 + }
  92 +
  93 + @Override
  94 + protected void onPause() {
  95 + super.onPause();
  96 + videoView.pause();
  97 + }
  98 +
  99 + @Override
  100 + protected void onResume() {
  101 + super.onResume();
  102 + videoView.start();
  103 + }
  104 +
  105 + @Override
  106 + protected void onDestroy() {
  107 + super.onDestroy();
  108 + videoView.release();
  109 + }
  110 +
  111 + public void switchClick(View v) {
  112 + String rate = "";
  113 + switch (v.getId()) {
  114 + case R.id.rateL:
  115 + switchRate = rateL;
  116 + rate = Config.TYPE_PLAY_RATE_1;
  117 + break;
  118 + case R.id.rateM:
  119 + switchRate = rateM;
  120 + rate = Config.TYPE_PLAY_RATE_2;
  121 + break;
  122 + case R.id.rateH:
  123 + switchRate = rateH;
  124 + rate = Config.TYPE_PLAY_RATE_3;
  125 + break;
  126 + case R.id.rateHH:
  127 + switchRate = rateHH;
  128 + rate = Config.TYPE_PLAY_RATE_4;
  129 + break;
  130 + }
  131 + loading.setVisibility(View.VISIBLE);
  132 +// videoView.switchVideo(new DataSource("82_liveshow", Config.TYPE_LIVE, rate));
  133 + videoView.switchVideo(new DataSource("82_58ff2c30f4714a04a77f854f50d86e3a", Config.TYPE_VOD, rate));
  134 + }
  135 +
  136 + @Override
  137 + public void onSwitchVideoPrepared(IMediaPlayer mediaplayer) {
  138 + videoView.switchVideoStart(videoView.getCurrentPosition());//点播使用此方法
  139 +// videoView.switchVideoStart();//直播使用此方法
  140 + }
  141 +
  142 + @Override
  143 + public void onSwitchVideoComplete(IMediaPlayer mediaplayer) {
  144 + loading.setVisibility(View.GONE);
  145 + curRate = switchRate;
  146 + setSelectRate(curRate);
  147 + Toast.makeText(this, "切换成功", Toast.LENGTH_LONG).show();
  148 + }
  149 +
  150 + @Override
  151 + public void onSwitchVideoError(IMediaPlayer mediaplayer, int what, int extra) {
  152 + videoView.releaseSwitchVideo();
  153 + loading.setVisibility(View.GONE);
  154 + Toast.makeText(this, "切换失败", Toast.LENGTH_LONG).show();
  155 + }
  156 +
  157 + @Override
  158 + public boolean onInfo(IMediaPlayer mediaplayer, int what, int extra) {
  159 + return false;
  160 + }
  161 +
  162 + @Override
  163 + public boolean onError(IMediaPlayer mediaplayer, int what, int extra) {
  164 + loading.setVisibility(View.GONE);
  165 + Toast.makeText(this, "error", Toast.LENGTH_LONG).show();
  166 + return false;
  167 + }
  168 +
  169 + @Override
  170 + public void onSeekComplete(IMediaPlayer mediaplayer) {
  171 +
  172 + }
  173 +
  174 + @Override
  175 + public void onCompletion(IMediaPlayer mediaplayer) {
  176 +
  177 + }
  178 +
  179 + @Override
  180 + public void onPrepared(IMediaPlayer mediaplayer) {
  181 + loading.setVisibility(View.GONE);
  182 + mediaplayer.start();
  183 + }
  184 +
  185 + @Override
  186 + public void onPlayState(boolean isPlay) {
  187 +
  188 + }
  189 +
  190 +}
... ...
app/src/main/java/com/cnlive/demo/video/SwitchVideoByIdActivity.java
... ... @@ -27,7 +27,7 @@ public class SwitchVideoByIdActivity extends AppCompatActivity implements IMedia
27 27 @Override
28 28 protected void onCreate(@Nullable Bundle savedInstanceState) {
29 29 super.onCreate(savedInstanceState);
30   - setContentView(R.layout.activity_switch_video);
  30 + setContentView(R.layout.activity_switch_video_list);
31 31 initPlay();
32 32 startPlayId(getVideoIdList());
33 33 }
... ...
app/src/main/java/com/cnlive/demo/video/SwitchVideoByPathActivity.java
... ... @@ -24,7 +24,7 @@ public class SwitchVideoByPathActivity extends AppCompatActivity implements IMed
24 24 @Override
25 25 protected void onCreate(@Nullable Bundle savedInstanceState) {
26 26 super.onCreate(savedInstanceState);
27   - setContentView(R.layout.activity_switch_video);
  27 + setContentView(R.layout.activity_switch_video_list);
28 28 initPlay();
29 29 startPlay(getVideoList());
30 30 }
... ...
app/src/main/res/layout/activity_jump_switch.xml
... ... @@ -16,4 +16,10 @@
16 16 android:text="播放id的demo"
17 17 android:onClick="clickToPlayIdDemo"/>
18 18  
  19 + <Button
  20 + android:layout_width="wrap_content"
  21 + android:layout_height="wrap_content"
  22 + android:text="切换码率的demo"
  23 + android:onClick="clickToRateDemo"/>
  24 +
19 25 </LinearLayout>
20 26 \ No newline at end of file
... ...
app/src/main/res/layout/activity_switch_video.xml
1 1 <?xml version="1.0" encoding="utf-8"?>
2   -<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3   - xmlns:tools="http://schemas.android.com/tools"
4   - android:id="@+id/activity_test"
  2 +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
5 3 android:layout_width="match_parent"
6 4 android:layout_height="match_parent"
7   - tools:context="com.cnlive.demo.video.SwitchVideoByIdActivity">
  5 + android:orientation="vertical">
8 6  
9 7 <RelativeLayout
10 8 android:layout_width="match_parent"
... ... @@ -16,6 +14,41 @@
16 14 android:layout_width="match_parent"
17 15 android:layout_height="match_parent"
18 16 android:layout_centerInParent="true" />
  17 +
  18 + <ProgressBar
  19 + android:id="@+id/loading"
  20 + android:layout_width="50dp"
  21 + android:layout_height="50dp"
  22 + android:layout_centerInParent="true"
  23 + android:visibility="gone"/>
19 24 </RelativeLayout>
20 25  
21   -</RelativeLayout>
  26 + <Button
  27 + android:id="@+id/rateL"
  28 + android:layout_width="wrap_content"
  29 + android:layout_height="wrap_content"
  30 + android:text="流畅"
  31 + android:onClick="switchClick"/>
  32 +
  33 + <Button
  34 + android:id="@+id/rateM"
  35 + android:layout_width="wrap_content"
  36 + android:layout_height="wrap_content"
  37 + android:text="标清"
  38 + android:onClick="switchClick"/>
  39 +
  40 + <Button
  41 + android:id="@+id/rateH"
  42 + android:layout_width="wrap_content"
  43 + android:layout_height="wrap_content"
  44 + android:text="高清"
  45 + android:onClick="switchClick"/>
  46 +
  47 + <Button
  48 + android:id="@+id/rateHH"
  49 + android:layout_width="wrap_content"
  50 + android:layout_height="wrap_content"
  51 + android:text="超高清"
  52 + android:onClick="switchClick"/>
  53 +
  54 +</LinearLayout>
22 55 \ No newline at end of file
... ...
app/src/main/res/layout/activity_switch_video_list.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + xmlns:tools="http://schemas.android.com/tools"
  4 + android:id="@+id/activity_test"
  5 + android:layout_width="match_parent"
  6 + android:layout_height="match_parent"
  7 + tools:context="com.cnlive.demo.video.SwitchVideoByIdActivity">
  8 +
  9 + <RelativeLayout
  10 + android:layout_width="match_parent"
  11 + android:layout_height="200dp"
  12 + android:background="#000000">
  13 +
  14 + <com.cnlive.libs.video.video.SwitchVideoView
  15 + android:id="@+id/videoview"
  16 + android:layout_width="match_parent"
  17 + android:layout_height="match_parent"
  18 + android:layout_centerInParent="true" />
  19 + </RelativeLayout>
  20 +
  21 +</RelativeLayout>
... ...
app/src/main/res/values/colors.xml
... ... @@ -3,4 +3,7 @@
3 3 <color name="colorPrimary">#3F51B5</color>
4 4 <color name="colorPrimaryDark">#303F9F</color>
5 5 <color name="colorAccent">#FF4081</color>
  6 +
  7 + <color name="colorRateSel">#FF0000</color>
  8 + <color name="colorRateNor">#000000</color>
6 9 </resources>
... ...
doc/Android播放SDK说明文档 .pdf
No preview for this file type