Commit 899a4dc2b96901d5c1cebe00a34465ccd9626e12
1 parent
172a2e15
修改无缝切换的demo
Showing
8 changed files
with
225 additions
and
43 deletions
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.app.Activity; | |
| 4 | +import android.content.Intent; | |
| 5 | +import android.os.Bundle; | |
| 6 | +import android.support.annotation.Nullable; | |
| 7 | +import android.support.v7.app.AppCompatActivity; | |
| 8 | +import android.view.View; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * Created by gujun on 2017/5/17. | |
| 12 | + */ | |
| 13 | + | |
| 14 | +public class JumpSwitchVideoActivity extends AppCompatActivity{ | |
| 15 | + | |
| 16 | + @Override | |
| 17 | + protected void onCreate(@Nullable Bundle savedInstanceState) { | |
| 18 | + super.onCreate(savedInstanceState); | |
| 19 | + setContentView(R.layout.activity_jump_switch); | |
| 20 | + | |
| 21 | + } | |
| 22 | + | |
| 23 | + public void clickToPlayPathDemo(View view){ | |
| 24 | + startActivity(new Intent(this,SwitchVideoByIdActivity.class)); | |
| 25 | + } | |
| 26 | + | |
| 27 | + public void clickToPlayIdDemo(View view){ | |
| 28 | + startActivity(new Intent(this,SwitchVideoByPathActivity.class)); | |
| 29 | + } | |
| 30 | + | |
| 31 | + | |
| 32 | +} | |
| 33 | + | ... | ... |
app/src/main/java/com/cnlive/demo/video/MainActivity.java
| ... | ... | @@ -29,10 +29,10 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe |
| 29 | 29 | startActivity(new Intent(this, BarrageActivity.class)); |
| 30 | 30 | break; |
| 31 | 31 | case R.id.changePlayer: |
| 32 | - startActivity(new Intent(this, SwitchVideoActivity.class)); | |
| 32 | + startActivity(new Intent(this, JumpSwitchVideoActivity.class)); | |
| 33 | 33 | break; |
| 34 | 34 | case R.id.adVideo: |
| 35 | -// startActivity(new Intent(this, SltVideoActivity.class)); | |
| 35 | + startActivity(new Intent(this, SltVideoActivity.class)); | |
| 36 | 36 | break; |
| 37 | 37 | case R.id.videoStatus: |
| 38 | 38 | startActivity(new Intent(this, VideoStatusActivity.class)); | ... | ... |
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/SwitchVideoActivity.java renamed to app/src/main/java/com/cnlive/demo/video/SwitchVideoByPathActivity.java
| ... | ... | @@ -4,34 +4,29 @@ import android.os.Bundle; |
| 4 | 4 | import android.support.annotation.Nullable; |
| 5 | 5 | import android.support.v7.app.AppCompatActivity; |
| 6 | 6 | |
| 7 | -import com.cnlive.demo.video.model.DataSource; | |
| 8 | -import com.cnlive.libs.util.Config; | |
| 9 | 7 | import com.cnlive.libs.video.video.SwitchVideoView; |
| 10 | -import com.cnlive.libs.video.video.base.IDataSource; | |
| 11 | 8 | import com.cnlive.libs.video.video.base.IMediaPlayer; |
| 12 | 9 | import com.cnlive.libs.video.video.base.ISwitchVideoView; |
| 13 | 10 | |
| 14 | 11 | import java.util.ArrayList; |
| 15 | 12 | import java.util.List; |
| 16 | 13 | |
| 17 | -public class SwitchVideoActivity extends AppCompatActivity implements IMediaPlayer.OnPreparedListener, | |
| 14 | +public class SwitchVideoByPathActivity extends AppCompatActivity implements IMediaPlayer.OnPreparedListener, | |
| 18 | 15 | IMediaPlayer.OnCompletionListener, IMediaPlayer.OnErrorListener, IMediaPlayer.OnInfoListener, |
| 19 | 16 | IMediaPlayer.OnPlayStateListener, IMediaPlayer.OnSeekCompleteListener, |
| 20 | - ISwitchVideoView.OnSwitchVideoPreparedListener, ISwitchVideoView.OnSwitchVideoErrorListener{ | |
| 17 | + ISwitchVideoView.OnSwitchVideoPreparedListener, ISwitchVideoView.OnSwitchVideoErrorListener { | |
| 21 | 18 | |
| 22 | 19 | private SwitchVideoView videoView; |
| 23 | 20 | |
| 24 | - private int curVideoIndex=0; | |
| 21 | + private int curVideoIndex = 0; | |
| 25 | 22 | private List<String> videoUrls; |
| 26 | - private List<IDataSource> videoIdUrls; | |
| 27 | 23 | |
| 28 | 24 | @Override |
| 29 | 25 | protected void onCreate(@Nullable Bundle savedInstanceState) { |
| 30 | 26 | super.onCreate(savedInstanceState); |
| 31 | 27 | setContentView(R.layout.activity_switch_video); |
| 32 | 28 | initPlay(); |
| 33 | -// startPlay(getVideoList()); | |
| 34 | - startPlayId(getVideoIdList()); | |
| 29 | + startPlay(getVideoList()); | |
| 35 | 30 | } |
| 36 | 31 | |
| 37 | 32 | public List<String> getVideoList() { |
| ... | ... | @@ -56,28 +51,6 @@ public class SwitchVideoActivity extends AppCompatActivity implements IMediaPlay |
| 56 | 51 | return videoUrls.get(curVideoIndex++); |
| 57 | 52 | } |
| 58 | 53 | |
| 59 | - public List<IDataSource> getVideoIdList() { | |
| 60 | - List<IDataSource> videoList = new ArrayList<>(); | |
| 61 | - videoList.add(new DataSource("20161126",Config.TYPE_VOD,Config.TYPE_PLAY_RATE_2)); | |
| 62 | - videoList.add(new DataSource("20161126",Config.TYPE_VOD,Config.TYPE_PLAY_RATE_2)); | |
| 63 | - videoList.add(new DataSource("20161126",Config.TYPE_VOD,Config.TYPE_PLAY_RATE_2)); | |
| 64 | - videoList.add(new DataSource("20161126",Config.TYPE_VOD,Config.TYPE_PLAY_RATE_2)); | |
| 65 | - videoList.add(new DataSource("20161126",Config.TYPE_VOD,Config.TYPE_PLAY_RATE_2)); | |
| 66 | - return videoList; | |
| 67 | - } | |
| 68 | - | |
| 69 | - private void startPlayId(List<IDataSource> videoList) { | |
| 70 | - videoIdUrls = videoList; | |
| 71 | - curVideoIndex = 0; | |
| 72 | - videoView.setDataSource(getNextVideoId()); | |
| 73 | - videoView.switchVideo(getNextVideoId()); | |
| 74 | - } | |
| 75 | - | |
| 76 | - private IDataSource getNextVideoId() { | |
| 77 | - if (curVideoIndex >= videoIdUrls.size()) return null; | |
| 78 | - return videoIdUrls.get(curVideoIndex++); | |
| 79 | - } | |
| 80 | - | |
| 81 | 54 | private void initPlay() { |
| 82 | 55 | videoView = (SwitchVideoView) findViewById(R.id.videoview); |
| 83 | 56 | //认证APP播放权限(使用视讯中国资源) |
| ... | ... | @@ -89,6 +62,7 @@ public class SwitchVideoActivity extends AppCompatActivity implements IMediaPlay |
| 89 | 62 | videoView.setOnSeekCompleteListener(this); |
| 90 | 63 | videoView.setOnSwitchVideoPreparedListener(this); |
| 91 | 64 | videoView.setOnSwitchVideoErrorListener(this); |
| 65 | + videoView.setKeepScreenOn(true); | |
| 92 | 66 | } |
| 93 | 67 | |
| 94 | 68 | private void playComplete() { |
| ... | ... | @@ -117,12 +91,11 @@ public class SwitchVideoActivity extends AppCompatActivity implements IMediaPlay |
| 117 | 91 | public void onCompletion(IMediaPlayer iMediaPlayer) { |
| 118 | 92 | boolean isLastMedia = |
| 119 | 93 | videoView.getSwitchMediaPlayer() == null || iMediaPlayer.equals(videoView.getSwitchMediaPlayer()); |
| 120 | - if(isLastMedia){ | |
| 94 | + if (isLastMedia) { | |
| 121 | 95 | playComplete(); |
| 122 | - }else{ | |
| 96 | + } else { | |
| 123 | 97 | videoView.switchVideoStart(); |
| 124 | -// videoView.switchVideo(getNextVideoPath()); | |
| 125 | - videoView.switchVideo(getNextVideoId()); | |
| 98 | + videoView.switchVideo(getNextVideoPath()); | |
| 126 | 99 | } |
| 127 | 100 | } |
| 128 | 101 | ... | ... |
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,12 +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 | - <com.cnlive.libs.video.video.SwitchVideoView | |
| 10 | - android:id="@+id/videoview" | |
| 9 | + <RelativeLayout | |
| 11 | 10 | android:layout_width="match_parent" |
| 12 | - android:layout_height="match_parent" | |
| 13 | - android:layout_centerInParent="true" /> | |
| 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> | |
| 14 | 20 | |
| 15 | 21 | </RelativeLayout> | ... | ... |