Commit 7bbc38af84e83b6d479acde6fdf6f0bffcaf89d2
Merge branch 'master' of bj.gitlab.cnlive.com:cnlive-team/CNVideoDemo
Showing
24 changed files
with
430 additions
and
185 deletions
.idea/misc.xml
| ... | ... | @@ -37,7 +37,7 @@ |
| 37 | 37 | <ConfirmationsSetting value="0" id="Add" /> |
| 38 | 38 | <ConfirmationsSetting value="0" id="Remove" /> |
| 39 | 39 | </component> |
| 40 | - <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> | |
| 40 | + <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> | |
| 41 | 41 | <output url="file://$PROJECT_DIR$/build/classes" /> |
| 42 | 42 | </component> |
| 43 | 43 | <component name="ProjectType"> | ... | ... |
app/build.gradle
| ... | ... | @@ -26,6 +26,6 @@ dependencies { |
| 26 | 26 | compile project(':lib_advideo') |
| 27 | 27 | compile 'com.android.support:appcompat-v7:25.0.0' |
| 28 | 28 | compile 'com.android.support.constraint:constraint-layout:1.0.1' |
| 29 | - compile 'com.android.support:design:25.3.0' | |
| 29 | + compile 'com.android.support:design:25.0.0' | |
| 30 | 30 | testCompile 'junit:junit:4.12' |
| 31 | 31 | } | ... | ... |
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
| ... | ... | @@ -46,7 +46,17 @@ |
| 46 | 46 | android:configChanges="keyboardHidden|screenSize|orientation" |
| 47 | 47 | android:screenOrientation="portrait" /> |
| 48 | 48 | <activity |
| 49 | - android:name=".SwitchVideoActivity" | |
| 49 | + android:name=".SwitchVideoByIdActivity" | |
| 50 | + android:configChanges="keyboardHidden|screenSize|orientation" | |
| 51 | + android:screenOrientation="portrait" /> | |
| 52 | + | |
| 53 | + <activity | |
| 54 | + android:name=".SwitchVideoByPathActivity" | |
| 55 | + android:configChanges="keyboardHidden|screenSize|orientation" | |
| 56 | + android:screenOrientation="portrait" /> | |
| 57 | + | |
| 58 | + <activity | |
| 59 | + android:name=".JumpSwitchVideoActivity" | |
| 50 | 60 | android:configChanges="keyboardHidden|screenSize|orientation" |
| 51 | 61 | android:screenOrientation="portrait" /> |
| 52 | 62 | ... | ... |
app/src/main/java/com/cnlive/demo/video/JumpSwitchVideoActivity.java
0 → 100644
| 1 | +package com.cnlive.demo.video; | |
| 2 | + | |
| 3 | +import android.content.Intent; | |
| 4 | +import android.os.Bundle; | |
| 5 | +import android.support.annotation.Nullable; | |
| 6 | +import android.support.v7.app.AppCompatActivity; | |
| 7 | +import android.view.View; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * Created by gujun on 2017/5/17. | |
| 11 | + */ | |
| 12 | + | |
| 13 | +public class JumpSwitchVideoActivity extends AppCompatActivity{ | |
| 14 | + | |
| 15 | + @Override | |
| 16 | + protected void onCreate(@Nullable Bundle savedInstanceState) { | |
| 17 | + super.onCreate(savedInstanceState); | |
| 18 | + setContentView(R.layout.activity_jump_switch); | |
| 19 | + | |
| 20 | + } | |
| 21 | + | |
| 22 | + public void clickToPlayPathDemo(View view){ | |
| 23 | + startActivity(new Intent(this,SwitchVideoByPathActivity.class)); | |
| 24 | + } | |
| 25 | + | |
| 26 | + public void clickToPlayIdDemo(View view){ | |
| 27 | + startActivity(new Intent(this,SwitchVideoByIdActivity.class)); | |
| 28 | + } | |
| 29 | + | |
| 30 | + | |
| 31 | +} | |
| 32 | + | ... | ... |
app/src/main/java/com/cnlive/demo/video/MainActivity.java
| ... | ... | @@ -31,7 +31,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe |
| 31 | 31 | startActivity(new Intent(this, BarrageActivity.class)); |
| 32 | 32 | break; |
| 33 | 33 | case R.id.changePlayer: |
| 34 | - startActivity(new Intent(this, SwitchVideoActivity.class)); | |
| 34 | + startActivity(new Intent(this, JumpSwitchVideoActivity.class)); | |
| 35 | 35 | break; |
| 36 | 36 | case R.id.adVideo: |
| 37 | 37 | startActivity(new Intent(this, SltVideoActivity.class)); | ... | ... |
app/src/main/java/com/cnlive/demo/video/SwitchVideoActivity.java deleted
100644 → 0
| 1 | -package com.cnlive.demo.video; | |
| 2 | - | |
| 3 | -import android.support.v7.app.AppCompatActivity; | |
| 4 | -import android.os.Bundle; | |
| 5 | -import android.view.SurfaceHolder; | |
| 6 | -import android.view.SurfaceView; | |
| 7 | -import android.view.View; | |
| 8 | -import android.widget.Button; | |
| 9 | -import android.widget.Toast; | |
| 10 | - | |
| 11 | -import com.cnlive.libs.video.video.MediaPlayer; | |
| 12 | -import com.cnlive.libs.video.video.base.IMediaPlayer; | |
| 13 | - | |
| 14 | -import java.io.IOException; | |
| 15 | - | |
| 16 | -public class SwitchVideoActivity extends AppCompatActivity { | |
| 17 | - | |
| 18 | - private MediaPlayer firstPlayer; | |
| 19 | - private MediaPlayer secondPlayer; | |
| 20 | - | |
| 21 | - //负责配合mediaPlayer显示视频图像播放的surfaceView | |
| 22 | - private SurfaceView surface; | |
| 23 | - private SurfaceHolder surfaceHolder; | |
| 24 | - | |
| 25 | - private boolean isFirst = true; | |
| 26 | - | |
| 27 | - private Button changeBtn; | |
| 28 | - private Button prepareBtn; | |
| 29 | - | |
| 30 | - @Override | |
| 31 | - protected void onCreate(Bundle savedInstanceState) { | |
| 32 | - super.onCreate(savedInstanceState); | |
| 33 | - setContentView(R.layout.activity_switch_video); | |
| 34 | - | |
| 35 | - surface = (SurfaceView) findViewById(R.id.surfaceView); | |
| 36 | - surfaceHolder = surface.getHolder(); | |
| 37 | - changeBtn = (Button) findViewById(R.id.prepare); | |
| 38 | - changeBtn.setOnClickListener(listener); | |
| 39 | - | |
| 40 | - prepareBtn = (Button) findViewById(R.id.create); | |
| 41 | - prepareBtn.setOnClickListener(listener); | |
| 42 | - | |
| 43 | - initFirstPlayer(true); | |
| 44 | - } | |
| 45 | - | |
| 46 | - View.OnClickListener listener = new View.OnClickListener() { | |
| 47 | - @Override | |
| 48 | - public void onClick(View v) { | |
| 49 | - //判断切换到哪一个MediaPlayer | |
| 50 | - switch (v.getId()) { | |
| 51 | - case R.id.prepare: | |
| 52 | - if (isFirst && secondPlayer != null) { | |
| 53 | - //点击按钮切换到第二个MediaPlayer | |
| 54 | - firstPlayer.setDisplay(null); | |
| 55 | -// secondPlayer.setDisplay(surfaceHolder); | |
| 56 | - secondPlayer.setPlayerMute(0); | |
| 57 | - firstPlayer.release(); | |
| 58 | - firstPlayer = null; | |
| 59 | - isFirst = false; | |
| 60 | - } else if (!isFirst && firstPlayer != null){ | |
| 61 | - //点击按钮切换到第一个MediaPlayer | |
| 62 | - secondPlayer.setDisplay(null); | |
| 63 | -// firstPlayer.setDisplay(surfaceHolder); | |
| 64 | - firstPlayer.setPlayerMute(0); | |
| 65 | - secondPlayer.release(); | |
| 66 | - secondPlayer = null; | |
| 67 | - isFirst = true; | |
| 68 | - }else { | |
| 69 | - Toast.makeText(SwitchVideoActivity.this, "Player为null,请先准备视频", Toast.LENGTH_SHORT).show(); | |
| 70 | - } | |
| 71 | - break; | |
| 72 | - case R.id.create: | |
| 73 | - if (firstPlayer == null) { | |
| 74 | - initFirstPlayer(false); | |
| 75 | - } | |
| 76 | - if (secondPlayer == null) | |
| 77 | - initNextPlayer(); | |
| 78 | - } | |
| 79 | - } | |
| 80 | - }; | |
| 81 | - | |
| 82 | - private void initFirstPlayer(final boolean isFirstTime) { | |
| 83 | - //初始化第一个MediaPlayer,在本demo中需要传入是否是第一次初始化,如果不是第一次则需要将player设置为静音 | |
| 84 | - firstPlayer = new MediaPlayer(getBaseContext()); | |
| 85 | - firstPlayer.setOnPreparedListener(new IMediaPlayer.OnPreparedListener() { | |
| 86 | - @Override | |
| 87 | - public void onPrepared(IMediaPlayer iMediaPlayer) { | |
| 88 | - firstPlayer.setDisplay(surfaceHolder); | |
| 89 | - firstPlayer.start(); | |
| 90 | - if (isFirstTime) { | |
| 91 | - firstPlayer.setPlayerMute(0); | |
| 92 | - } else { | |
| 93 | - firstPlayer.setPlayerMute(1); | |
| 94 | - } | |
| 95 | - } | |
| 96 | - }); | |
| 97 | - | |
| 98 | - firstPlayer.setBufferTimeMax(3); | |
| 99 | - firstPlayer.setTimeout(5, 30); | |
| 100 | - | |
| 101 | - | |
| 102 | - try { | |
| 103 | - firstPlayer.setDataSource("rtmp://live.hkstv.hk.lxdns.com/live/hks"); | |
| 104 | - firstPlayer.prepareAsync(); | |
| 105 | - } catch (IOException e) { | |
| 106 | - e.printStackTrace(); | |
| 107 | - } | |
| 108 | - } | |
| 109 | - | |
| 110 | - private void initNextPlayer() { | |
| 111 | - //初始化第二个MediaPlayer | |
| 112 | - secondPlayer = new MediaPlayer(SwitchVideoActivity.this); | |
| 113 | - secondPlayer.setOnPreparedListener(new IMediaPlayer.OnPreparedListener() { | |
| 114 | - @Override | |
| 115 | - public void onPrepared(IMediaPlayer iMediaPlayer) { | |
| 116 | - secondPlayer.setDisplay(surfaceHolder); | |
| 117 | - secondPlayer.start(); | |
| 118 | - secondPlayer.setPlayerMute(1); | |
| 119 | - } | |
| 120 | - }); | |
| 121 | - | |
| 122 | - secondPlayer.setBufferTimeMax(3); | |
| 123 | - secondPlayer.setTimeout(5, 30); | |
| 124 | - | |
| 125 | - try { | |
| 126 | - secondPlayer.setDataSource("http://uv01.cnlive.com/record/live/82_20161126/hls/82_20161126-82_20161126.m3u8"); | |
| 127 | - secondPlayer.prepareAsync(); | |
| 128 | - } catch (IOException e) { | |
| 129 | - e.printStackTrace(); | |
| 130 | - } | |
| 131 | - | |
| 132 | - } | |
| 133 | - | |
| 134 | - | |
| 135 | - @Override | |
| 136 | - protected void onResume() { | |
| 137 | - super.onResume(); | |
| 138 | - if (firstPlayer != null) { | |
| 139 | - firstPlayer.start(); | |
| 140 | - } | |
| 141 | - if (secondPlayer != null) { | |
| 142 | - secondPlayer.start(); | |
| 143 | - } | |
| 144 | - } | |
| 145 | - | |
| 146 | - @Override | |
| 147 | - protected void onDestroy() { | |
| 148 | - super.onDestroy(); | |
| 149 | - if (firstPlayer != null) { | |
| 150 | - if (firstPlayer.isPlaying()) { | |
| 151 | - firstPlayer.stop(); | |
| 152 | - } | |
| 153 | - firstPlayer.release(); | |
| 154 | - } | |
| 155 | - if (secondPlayer != null) { | |
| 156 | - if (secondPlayer.isPlaying()) { | |
| 157 | - secondPlayer.stop(); | |
| 158 | - } | |
| 159 | - secondPlayer.release(); | |
| 160 | - } | |
| 161 | - | |
| 162 | - } | |
| 163 | -} |
app/src/main/java/com/cnlive/demo/video/SwitchVideoByIdActivity.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 | + | |
| 7 | +import com.cnlive.demo.video.model.DataSource; | |
| 8 | +import com.cnlive.libs.util.Config; | |
| 9 | +import com.cnlive.libs.video.video.SwitchVideoView; | |
| 10 | +import com.cnlive.libs.video.video.base.IDataSource; | |
| 11 | +import com.cnlive.libs.video.video.base.IMediaPlayer; | |
| 12 | +import com.cnlive.libs.video.video.base.ISwitchVideoView; | |
| 13 | + | |
| 14 | +import java.util.ArrayList; | |
| 15 | +import java.util.List; | |
| 16 | + | |
| 17 | +public class SwitchVideoByIdActivity extends AppCompatActivity implements IMediaPlayer.OnPreparedListener, | |
| 18 | + IMediaPlayer.OnCompletionListener, IMediaPlayer.OnErrorListener, IMediaPlayer.OnInfoListener, | |
| 19 | + IMediaPlayer.OnPlayStateListener, IMediaPlayer.OnSeekCompleteListener, | |
| 20 | + ISwitchVideoView.OnSwitchVideoPreparedListener, ISwitchVideoView.OnSwitchVideoErrorListener { | |
| 21 | + | |
| 22 | + private SwitchVideoView videoView; | |
| 23 | + | |
| 24 | + private int curVideoIndex = 0; | |
| 25 | + private List<IDataSource> videoIdUrls; | |
| 26 | + | |
| 27 | + @Override | |
| 28 | + protected void onCreate(@Nullable Bundle savedInstanceState) { | |
| 29 | + super.onCreate(savedInstanceState); | |
| 30 | + setContentView(R.layout.activity_switch_video); | |
| 31 | + initPlay(); | |
| 32 | + startPlayId(getVideoIdList()); | |
| 33 | + } | |
| 34 | + | |
| 35 | + public List<IDataSource> getVideoIdList() { | |
| 36 | + List<IDataSource> videoList = new ArrayList<>(); | |
| 37 | + videoList.add(new DataSource("20161126", Config.TYPE_VOD, Config.TYPE_PLAY_RATE_2)); | |
| 38 | + videoList.add(new DataSource("20161126", Config.TYPE_VOD, Config.TYPE_PLAY_RATE_2)); | |
| 39 | + videoList.add(new DataSource("20161126", Config.TYPE_VOD, Config.TYPE_PLAY_RATE_2)); | |
| 40 | + videoList.add(new DataSource("20161126", Config.TYPE_VOD, Config.TYPE_PLAY_RATE_2)); | |
| 41 | + videoList.add(new DataSource("20161126", Config.TYPE_VOD, Config.TYPE_PLAY_RATE_2)); | |
| 42 | + return videoList; | |
| 43 | + } | |
| 44 | + | |
| 45 | + private void startPlayId(List<IDataSource> videoList) { | |
| 46 | + videoIdUrls = videoList; | |
| 47 | + curVideoIndex = 0; | |
| 48 | + videoView.setDataSource(getNextVideoId()); | |
| 49 | + videoView.switchVideo(getNextVideoId()); | |
| 50 | + } | |
| 51 | + | |
| 52 | + private IDataSource getNextVideoId() { | |
| 53 | + if (curVideoIndex >= videoIdUrls.size()) return null; | |
| 54 | + return videoIdUrls.get(curVideoIndex++); | |
| 55 | + } | |
| 56 | + | |
| 57 | + private void initPlay() { | |
| 58 | + videoView = (SwitchVideoView) findViewById(R.id.videoview); | |
| 59 | + //认证APP播放权限(使用视讯中国资源) | |
| 60 | + videoView.setOnPreparedListener(this); | |
| 61 | + videoView.setOnCompletionListener(this); | |
| 62 | + videoView.setOnPlayStateListener(this); | |
| 63 | + videoView.setOnErrorListener(this); | |
| 64 | + videoView.setOnInfoListener(this); | |
| 65 | + videoView.setOnSeekCompleteListener(this); | |
| 66 | + videoView.setOnSwitchVideoPreparedListener(this); | |
| 67 | + videoView.setOnSwitchVideoErrorListener(this); | |
| 68 | + videoView.setKeepScreenOn(true); | |
| 69 | + } | |
| 70 | + | |
| 71 | + private void playComplete() { | |
| 72 | + //播放完成 (视频结束或错误结束都会被触发) | |
| 73 | + } | |
| 74 | + | |
| 75 | + @Override | |
| 76 | + protected void onPause() { | |
| 77 | + super.onPause(); | |
| 78 | + videoView.pause(); | |
| 79 | + } | |
| 80 | + | |
| 81 | + @Override | |
| 82 | + protected void onResume() { | |
| 83 | + super.onResume(); | |
| 84 | + videoView.start(); | |
| 85 | + } | |
| 86 | + | |
| 87 | + @Override | |
| 88 | + protected void onDestroy() { | |
| 89 | + super.onDestroy(); | |
| 90 | + videoView.release(); | |
| 91 | + } | |
| 92 | + | |
| 93 | + @Override | |
| 94 | + public void onCompletion(IMediaPlayer iMediaPlayer) { | |
| 95 | + boolean isLastMedia = | |
| 96 | + videoView.getSwitchMediaPlayer() == null || iMediaPlayer.equals(videoView.getSwitchMediaPlayer()); | |
| 97 | + if (isLastMedia) { | |
| 98 | + playComplete(); | |
| 99 | + } else { | |
| 100 | + videoView.switchVideoStart(); | |
| 101 | + videoView.switchVideo(getNextVideoId()); | |
| 102 | + } | |
| 103 | + } | |
| 104 | + | |
| 105 | + @Override | |
| 106 | + public boolean onError(IMediaPlayer iMediaPlayer, int i, int i1) { | |
| 107 | + videoView.releaseSwitchVideo(); | |
| 108 | + return false; | |
| 109 | + } | |
| 110 | + | |
| 111 | + @Override | |
| 112 | + public boolean onInfo(IMediaPlayer iMediaPlayer, int i, int i1) { | |
| 113 | + return false; | |
| 114 | + } | |
| 115 | + | |
| 116 | + @Override | |
| 117 | + public void onPlayState(boolean b) { | |
| 118 | + | |
| 119 | + } | |
| 120 | + | |
| 121 | + @Override | |
| 122 | + public void onPrepared(IMediaPlayer iMediaPlayer) { | |
| 123 | + iMediaPlayer.start(); | |
| 124 | + } | |
| 125 | + | |
| 126 | + @Override | |
| 127 | + public void onSeekComplete(IMediaPlayer iMediaPlayer) { | |
| 128 | + | |
| 129 | + } | |
| 130 | + | |
| 131 | + @Override | |
| 132 | + public void onSwitchVideoError(IMediaPlayer iMediaPlayer, int i, int i1) { | |
| 133 | + videoView.releaseSwitchVideo(); | |
| 134 | + } | |
| 135 | + | |
| 136 | + @Override | |
| 137 | + public void onSwitchVideoPrepared(IMediaPlayer iMediaPlayer) { | |
| 138 | + | |
| 139 | + } | |
| 140 | + | |
| 141 | +} | ... | ... |
app/src/main/java/com/cnlive/demo/video/SwitchVideoByPathActivity.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 | + | |
| 7 | +import com.cnlive.libs.video.video.SwitchVideoView; | |
| 8 | +import com.cnlive.libs.video.video.base.IMediaPlayer; | |
| 9 | +import com.cnlive.libs.video.video.base.ISwitchVideoView; | |
| 10 | + | |
| 11 | +import java.util.ArrayList; | |
| 12 | +import java.util.List; | |
| 13 | + | |
| 14 | +public class SwitchVideoByPathActivity extends AppCompatActivity implements IMediaPlayer.OnPreparedListener, | |
| 15 | + IMediaPlayer.OnCompletionListener, IMediaPlayer.OnErrorListener, IMediaPlayer.OnInfoListener, | |
| 16 | + IMediaPlayer.OnPlayStateListener, IMediaPlayer.OnSeekCompleteListener, | |
| 17 | + ISwitchVideoView.OnSwitchVideoPreparedListener, ISwitchVideoView.OnSwitchVideoErrorListener { | |
| 18 | + | |
| 19 | + private SwitchVideoView videoView; | |
| 20 | + | |
| 21 | + private int curVideoIndex = 0; | |
| 22 | + private List<String> videoUrls; | |
| 23 | + | |
| 24 | + @Override | |
| 25 | + protected void onCreate(@Nullable Bundle savedInstanceState) { | |
| 26 | + super.onCreate(savedInstanceState); | |
| 27 | + setContentView(R.layout.activity_switch_video); | |
| 28 | + initPlay(); | |
| 29 | + startPlay(getVideoList()); | |
| 30 | + } | |
| 31 | + | |
| 32 | + public List<String> getVideoList() { | |
| 33 | + List<String> videoList = new ArrayList<>(); | |
| 34 | + videoList.add("https://mobile.cnlive.com/CnliveMobile/web/7.mp4"); | |
| 35 | + videoList.add("https://mobile.cnlive.com/CnliveMobile/web/7.mp4"); | |
| 36 | + videoList.add("https://mobile.cnlive.com/CnliveMobile/web/7.mp4"); | |
| 37 | + videoList.add("https://mobile.cnlive.com/CnliveMobile/web/7.mp4"); | |
| 38 | + videoList.add("https://mobile.cnlive.com/CnliveMobile/web/7.mp4"); | |
| 39 | + return videoList; | |
| 40 | + } | |
| 41 | + | |
| 42 | + private void startPlay(List<String> videoList) { | |
| 43 | + videoUrls = videoList; | |
| 44 | + curVideoIndex = 0; | |
| 45 | + videoView.setDataSource(getNextVideoPath()); | |
| 46 | + videoView.switchVideo(getNextVideoPath()); | |
| 47 | + } | |
| 48 | + | |
| 49 | + private String getNextVideoPath() { | |
| 50 | + if (curVideoIndex >= videoUrls.size()) return null; | |
| 51 | + return videoUrls.get(curVideoIndex++); | |
| 52 | + } | |
| 53 | + | |
| 54 | + private void initPlay() { | |
| 55 | + videoView = (SwitchVideoView) findViewById(R.id.videoview); | |
| 56 | + //认证APP播放权限(使用视讯中国资源) | |
| 57 | + videoView.setOnPreparedListener(this); | |
| 58 | + videoView.setOnCompletionListener(this); | |
| 59 | + videoView.setOnPlayStateListener(this); | |
| 60 | + videoView.setOnErrorListener(this); | |
| 61 | + videoView.setOnInfoListener(this); | |
| 62 | + videoView.setOnSeekCompleteListener(this); | |
| 63 | + videoView.setOnSwitchVideoPreparedListener(this); | |
| 64 | + videoView.setOnSwitchVideoErrorListener(this); | |
| 65 | + videoView.setKeepScreenOn(true); | |
| 66 | + } | |
| 67 | + | |
| 68 | + private void playComplete() { | |
| 69 | + //播放完成 (视频结束或错误结束都会被触发) | |
| 70 | + } | |
| 71 | + | |
| 72 | + @Override | |
| 73 | + protected void onPause() { | |
| 74 | + super.onPause(); | |
| 75 | + videoView.pause(); | |
| 76 | + } | |
| 77 | + | |
| 78 | + @Override | |
| 79 | + protected void onResume() { | |
| 80 | + super.onResume(); | |
| 81 | + videoView.start(); | |
| 82 | + } | |
| 83 | + | |
| 84 | + @Override | |
| 85 | + protected void onDestroy() { | |
| 86 | + super.onDestroy(); | |
| 87 | + videoView.release(); | |
| 88 | + } | |
| 89 | + | |
| 90 | + @Override | |
| 91 | + public void onCompletion(IMediaPlayer iMediaPlayer) { | |
| 92 | + boolean isLastMedia = | |
| 93 | + videoView.getSwitchMediaPlayer() == null || iMediaPlayer.equals(videoView.getSwitchMediaPlayer()); | |
| 94 | + if (isLastMedia) { | |
| 95 | + playComplete(); | |
| 96 | + } else { | |
| 97 | + videoView.switchVideoStart(); | |
| 98 | + videoView.switchVideo(getNextVideoPath()); | |
| 99 | + } | |
| 100 | + } | |
| 101 | + | |
| 102 | + @Override | |
| 103 | + public boolean onError(IMediaPlayer iMediaPlayer, int i, int i1) { | |
| 104 | + videoView.releaseSwitchVideo(); | |
| 105 | + return false; | |
| 106 | + } | |
| 107 | + | |
| 108 | + @Override | |
| 109 | + public boolean onInfo(IMediaPlayer iMediaPlayer, int i, int i1) { | |
| 110 | + return false; | |
| 111 | + } | |
| 112 | + | |
| 113 | + @Override | |
| 114 | + public void onPlayState(boolean b) { | |
| 115 | + | |
| 116 | + } | |
| 117 | + | |
| 118 | + @Override | |
| 119 | + public void onPrepared(IMediaPlayer iMediaPlayer) { | |
| 120 | + iMediaPlayer.start(); | |
| 121 | + } | |
| 122 | + | |
| 123 | + @Override | |
| 124 | + public void onSeekComplete(IMediaPlayer iMediaPlayer) { | |
| 125 | + | |
| 126 | + } | |
| 127 | + | |
| 128 | + @Override | |
| 129 | + public void onSwitchVideoError(IMediaPlayer iMediaPlayer, int i, int i1) { | |
| 130 | + videoView.releaseSwitchVideo(); | |
| 131 | + } | |
| 132 | + | |
| 133 | + @Override | |
| 134 | + public void onSwitchVideoPrepared(IMediaPlayer iMediaPlayer) { | |
| 135 | + | |
| 136 | + } | |
| 137 | + | |
| 138 | +} | ... | ... |
app/src/main/java/com/cnlive/demo/video/VideoViewActivity.java
| ... | ... | @@ -51,13 +51,17 @@ public class VideoViewActivity extends Activity { |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | private void startPlay() { |
| 54 | -// //视讯云 直播 | |
| 55 | -// videoView.setDataSource(new ProgramLive(),false); | |
| 56 | 54 | |
| 57 | 55 | //视讯云 点播 |
| 58 | 56 | videoView.setDataSource(new ProgramVod()); |
| 59 | 57 | |
| 60 | -// //本地视频 | |
| 58 | + //视讯云 直播 主播/频道ID播放 | |
| 59 | + //videoView.setDataSource(new ProgramLive()); | |
| 60 | + | |
| 61 | + //视讯云 直播 活动ID播放 | |
| 62 | + //videoView.setDataSource(new ProgramLiveActivityId()); | |
| 63 | + | |
| 64 | + //本地视频 | |
| 61 | 65 | // try { |
| 62 | 66 | // videoView.setDataSource("rtmp://live.hkstv.hk.lxdns.com/live/hks"); |
| 63 | 67 | // } catch (IOException e) { | ... | ... |
app/src/main/java/com/cnlive/demo/video/model/DataSource.java
0 → 100644
| 1 | +package com.cnlive.demo.video.model; | |
| 2 | + | |
| 3 | +import com.cnlive.libs.video.video.base.IDataSource; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * Created by gujun on 2017/5/16. | |
| 7 | + */ | |
| 8 | + | |
| 9 | +public class DataSource implements IDataSource{ | |
| 10 | + | |
| 11 | + private String id; | |
| 12 | + private String type; | |
| 13 | + private String rate; | |
| 14 | + | |
| 15 | + public DataSource(String id, String type, String rate) { | |
| 16 | + this.id = id; | |
| 17 | + this.type = type; | |
| 18 | + this.rate = rate; | |
| 19 | + } | |
| 20 | + | |
| 21 | + @Override | |
| 22 | + public String getDataSourceId() { | |
| 23 | + return id; | |
| 24 | + } | |
| 25 | + | |
| 26 | + @Override | |
| 27 | + public String getDataSourceType() { | |
| 28 | + return type; | |
| 29 | + } | |
| 30 | + | |
| 31 | + @Override | |
| 32 | + public String getDataSourceRate() { | |
| 33 | + return rate; | |
| 34 | + } | |
| 35 | +} | ... | ... |
app/src/main/java/com/cnlive/demo/video/model/ProgramLiveActivityId.java
0 → 100644
| 1 | +package com.cnlive.demo.video.model; | |
| 2 | + | |
| 3 | +import com.cnlive.libs.util.Config; | |
| 4 | +import com.cnlive.libs.video.video.base.IActivityDataSource; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * Created by xiansong on 2017/6/20. | |
| 8 | + */ | |
| 9 | + | |
| 10 | +public class ProgramLiveActivityId implements IActivityDataSource { | |
| 11 | + | |
| 12 | + @Override | |
| 13 | + public String getDataSourceId() { | |
| 14 | + //TODO 主播/频道ID | |
| 15 | + return "androidtest"; | |
| 16 | + } | |
| 17 | + | |
| 18 | + //返回视频类型 live | |
| 19 | + @Override | |
| 20 | + public String getDataSourceType() { | |
| 21 | + return Config.TYPE_LIVE; | |
| 22 | + } | |
| 23 | + | |
| 24 | + //返回视频码率 | |
| 25 | + @Override | |
| 26 | + public String getDataSourceRate() { | |
| 27 | + return Config.TYPE_PLAY_RATE_2; | |
| 28 | + } | |
| 29 | + | |
| 30 | + @Override | |
| 31 | + public String getDataActivityId() { | |
| 32 | + //TODO 通过活动ID播放 | |
| 33 | + return "activityId"; | |
| 34 | + } | |
| 35 | +} | ... | ... |
app/src/main/jniLibs/arm64-v8a/libRongIMLib.so
No preview for this file type
app/src/main/jniLibs/arm64-v8a/libksylive.so
No preview for this file type
app/src/main/jniLibs/armeabi-v7a/libRongIMLib.so
No preview for this file type
app/src/main/jniLibs/armeabi-v7a/libksylive.so
No preview for this file type
app/src/main/jniLibs/armeabi/libRongIMLib.so
No preview for this file type
app/src/main/jniLibs/armeabi/libksylive.so
No preview for this file type
app/src/main/jniLibs/x86/libRongIMLib.so
No preview for this file type
app/src/main/jniLibs/x86/libksylive.so
No preview for this file type
app/src/main/res/layout/activity_jump_switch.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| 3 | + android:layout_width="match_parent" | |
| 4 | + android:layout_height="match_parent" | |
| 5 | + android:orientation="vertical"> | |
| 6 | + | |
| 7 | + <Button | |
| 8 | + android:layout_width="wrap_content" | |
| 9 | + android:layout_height="wrap_content" | |
| 10 | + android:text="播放地址的demo" | |
| 11 | + android:onClick="clickToPlayPathDemo"/> | |
| 12 | + | |
| 13 | + <Button | |
| 14 | + android:layout_width="wrap_content" | |
| 15 | + android:layout_height="wrap_content" | |
| 16 | + android:text="播放id的demo" | |
| 17 | + android:onClick="clickToPlayIdDemo"/> | |
| 18 | + | |
| 19 | +</LinearLayout> | |
| 0 | 20 | \ No newline at end of file | ... | ... |
app/src/main/res/layout/activity_switch_video.xml
| ... | ... | @@ -4,24 +4,18 @@ |
| 4 | 4 | android:id="@+id/activity_test" |
| 5 | 5 | android:layout_width="match_parent" |
| 6 | 6 | android:layout_height="match_parent" |
| 7 | - tools:context="com.cnlive.demo.video.SwitchVideoActivity"> | |
| 7 | + tools:context="com.cnlive.demo.video.SwitchVideoByIdActivity"> | |
| 8 | 8 | |
| 9 | - <SurfaceView | |
| 10 | - android:id="@+id/surfaceView" | |
| 9 | + <RelativeLayout | |
| 11 | 10 | android:layout_width="match_parent" |
| 12 | 11 | android:layout_height="200dp" |
| 13 | - android:layout_centerInParent="true" /> | |
| 12 | + android:background="#000000"> | |
| 14 | 13 | |
| 15 | - <Button | |
| 16 | - android:id="@+id/prepare" | |
| 17 | - android:layout_width="match_parent" | |
| 18 | - android:layout_height="wrap_content" | |
| 19 | - android:layout_below="@+id/create" | |
| 20 | - android:text="播放视频" /> | |
| 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> | |
| 21 | 20 | |
| 22 | - <Button | |
| 23 | - android:id="@+id/create" | |
| 24 | - android:layout_width="match_parent" | |
| 25 | - android:layout_height="wrap_content" | |
| 26 | - android:text="准备视频" /> | |
| 27 | 21 | </RelativeLayout> | ... | ... |
doc/Android播放SDK说明文档 .pdf
No preview for this file type