Skip to content

Commit

Permalink
Exoplayer 버전 업그레이드에 따른 변경사항 수정 작업 (r2.5.1 -> 2.12.1)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoohyungyu94 committed Feb 18, 2021
1 parent f7f267a commit 62ff36b
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 151 deletions.
20 changes: 4 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ WECANDEO 통계를 사용하기 위해서는 활성화 된 WECANDEO 계정이


### 1. 라이브러리 추가
implementation 'com.google.android.exoplayer:exoplayer:r2.5.1'
implementation 'com.google.android.exoplayer:exoplayer-core:r2.5.1'
implementation 'com.google.android.exoplayer:exoplayer-ui:r2.5.1'
implementation 'com.google.android.exoplayer:exoplayer:2.12.1'
implementation 'com.android.volley:volley:1.1.1'
implementation 'com.google.code.gson:gson:2.8.6'
implementation files('libs/WecandeoPlaySdk.jar')
Expand All @@ -41,21 +39,11 @@ WECANDEO 통계를 사용하기 위해서는 활성화 된 WECANDEO 계정이
<uses-permission android:name="android.permission.INTERNET" />
```

### 3. AndroidManifest.xml 에 networkSecurityConfig 설정
### 3. AndroidManifest.xml application 태그 안에 usesCleartextTraffic 설정
```
<application
...
android:networkSecurityConfig="@xml/network_security_config">
```
- res 폴더 안에 xml 폴더 추가 / xml 폴더에 network_security_config.xml 파일 추가
- netowkr_security_config.xml 내용
```
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<!--Set application-wide security config using base-config tag.-->
<base-config cleartextTrafficPermitted="true"/>
</network-security-config>
```
android:usesCleartextTraffic="true">
```

### 4. LiveStatistics, VodStatistics, StatisticsUrlInfo, RequestSingleton Class 는 수정하지 않고 사용

Expand Down
4 changes: 1 addition & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.exoplayer:exoplayer:r2.5.1'
implementation 'com.google.android.exoplayer:exoplayer-core:r2.5.1'
implementation 'com.google.android.exoplayer:exoplayer-ui:r2.5.1'
implementation 'com.google.android.exoplayer:exoplayer:2.12.1'
implementation 'com.android.volley:volley:1.1.1'
implementation 'com.google.code.gson:gson:2.8.6'
testImplementation 'junit:junit:4.12'
Expand Down
Binary file modified app/libs/WecandeoPlaySdk.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:networkSecurityConfig="@xml/network_security_config"
android:usesCleartextTraffic="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Map<String, String> getHeaders() throws AuthFailureError {
}catch(PackageManager.NameNotFoundException e){
e.printStackTrace();
}
Map<String, String> headers = new HashMap<String, String>();
Map<String, String> headers = new HashMap<>();
headers.put("User-agent", userAgentInfo);
return headers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.ui.SimpleExoPlayerView;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.scenappsm.wecandeosdkplayer.SdkInterface;
Expand All @@ -30,11 +29,11 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;

public class LiveActivity extends AppCompatActivity implements View.OnClickListener, AdapterView.OnItemSelectedListener, ExoPlayer.EventListener, SdkInterface.onSdkListener{
public class LiveActivity extends AppCompatActivity implements View.OnClickListener, AdapterView.OnItemSelectedListener, Player.EventListener, SdkInterface.onSdkListener{

ConstraintLayout mainLayout;
ConstraintLayout liveParent;
SimpleExoPlayerView simpleExoPlayerView;
PlayerView playerView;

Button stopButton;
Button playButton;
Expand All @@ -50,7 +49,6 @@ public class LiveActivity extends AppCompatActivity implements View.OnClickListe
private boolean isPlayEnabled = false; // Live 재생 가능 여부

private static final String TAG = "LiveActivity";
private static final int PLAY_COMPLETE = 4; // 플레이 완료

String liveKey; // 발급 받은 liveKey 값을 입력

Expand All @@ -74,7 +72,7 @@ public void onDestroy(){
private void initViews(){
mainLayout = findViewById(R.id.main_layout);
liveParent = findViewById(R.id.live_parent);
simpleExoPlayerView = findViewById(R.id.live_view);
playerView = findViewById(R.id.live_view);
stopButton = findViewById(R.id.stop_button);
stopButton.setOnClickListener(this);
playButton = findViewById(R.id.play_button);
Expand All @@ -87,7 +85,7 @@ private void initViews(){
resizeSpinner.setAdapter(resizeSpinnerAdapter);
resizeSpinner.setOnItemSelectedListener(this);
resizeSpinner.bringToFront();
simpleExoPlayerView.setOnTouchListener(new View.OnTouchListener() {
playerView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(resizeSpinner.getVisibility() == View.VISIBLE){
Expand Down Expand Up @@ -120,9 +118,9 @@ public void onResponse(String response) {
JsonObject errorInfo = videoDetailObject.get("errorInfo").getAsJsonObject();
if(!errorInfo.get("errorCode").getAsString().equals("None")){
isPlayEnabled = false;
ViewGroup.LayoutParams params = simpleExoPlayerView.getLayoutParams();
ViewGroup.LayoutParams params = playerView.getLayoutParams();
params.height = 800;
simpleExoPlayerView.setLayoutParams(params);
playerView.setLayoutParams(params);
Toast.makeText(getApplicationContext(),"아직 방송시간이 아닙니다.",Toast.LENGTH_LONG).show();
}else{
// 현재 LIVE 방송 중일 경우 video setting
Expand All @@ -131,7 +129,7 @@ public void onResponse(String response) {
wecandeoVideo.setDrm(false);
wecandeoVideo.setVideoKey(videoKey);
wecandeoSdk.setWecandeoVideo(wecandeoVideo);
wecandeoSdk.setSimpleExoPlayerView(simpleExoPlayerView);
wecandeoSdk.setPlayerView(playerView);
//기본 컨트롤 뷰사용
wecandeoSdk.setUseController(false);
// 통계 연동
Expand Down Expand Up @@ -222,34 +220,22 @@ public void onSdkError(SimpleExoPlayer simpleExoPlayer, int i) {}
@Override
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {}

@Override
public void onLoadingChanged(boolean isLoading) {}


@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {

public void onPlaybackStateChanged(int playbackState) {
// 영상이 완료되었을 때
if(playWhenReady && playbackState == PLAY_COMPLETE && wecandeoSdk.getPlayer() != null){
if(playbackState == Player.STATE_ENDED && wecandeoSdk.getPlayer() != null){
wecandeoSdk.complete();
liveStatistics.sendStatistics(LiveStatistics.STOP);
}
}

@Override
public void onRepeatModeChanged(int repeatMode) {

}
public void onRepeatModeChanged(int repeatMode) {}

@Override
public void onPlayerError(ExoPlaybackException error) {}

@Override
public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {}

@Override
public void onTimelineChanged(Timeline timeline, Object manifest) {}

@Override
public void onPositionDiscontinuity() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.ui.SimpleExoPlayerView;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.scenappsm.wecandeosdkplayer.SdkInterface;
Expand All @@ -32,14 +31,12 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;

public class PlayerActivity extends AppCompatActivity implements View.OnClickListener, AdapterView.OnItemSelectedListener, ExoPlayer.EventListener, SdkInterface.onSdkListener{
public class PlayerActivity extends AppCompatActivity implements View.OnClickListener, AdapterView.OnItemSelectedListener, Player.EventListener, SdkInterface.onSdkListener{
WecandeoSdk wecandeoSdk;
WecandeoVideo wecandeoVideo;
VodStatistics vodStatistics; // 통계 연동 객체

private static final String TAG = "PlayerActivity";
private static final int PLAY_ENABLE = 3; // 즉시 플레이 가능
private static final int PLAY_COMPLETE = 4; // 플레이 완료
boolean isInitVideoInfo = true; // 플레이어가 준비 완료되면 true 이후 false (최초 한번만 실행)
boolean isPlaying = false; // 재생 시작 여부

Expand All @@ -48,7 +45,7 @@ public class PlayerActivity extends AppCompatActivity implements View.OnClickLis

ConstraintLayout mainLayout;
ConstraintLayout playerParent;
SimpleExoPlayerView simpleExoPlayerView;
PlayerView playerView;

Button retryButton;
Button stopButton;
Expand Down Expand Up @@ -87,7 +84,7 @@ protected void onCreate(Bundle savedInstanceState){
private void initViews(){
mainLayout = findViewById(R.id.main_layout);
playerParent = findViewById(R.id.player_parent);
simpleExoPlayerView = findViewById(R.id.player_view);
playerView = findViewById(R.id.player_view);
retryButton = findViewById(R.id.retry_button);
retryButton.setOnClickListener(this);
stopButton = findViewById(R.id.stop_button);
Expand Down Expand Up @@ -121,7 +118,7 @@ private void initViews(){
actionText = findViewById(R.id.action_text);
debugText = findViewById(R.id.debug_text);
resizeSpinner.bringToFront();
simpleExoPlayerView.setOnTouchListener(new View.OnTouchListener() {
playerView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(resizeSpinner.getVisibility() == View.VISIBLE){
Expand Down Expand Up @@ -150,7 +147,7 @@ private void initWecandeoSetting(){
wecandeoVideo.setVideoId(videoId);
wecandeoVideo.setSecretKey(secretKey);
wecandeoSdk.setWecandeoVideo(wecandeoVideo);
wecandeoSdk.setSimpleExoPlayerView(simpleExoPlayerView);
wecandeoSdk.setPlayerView(playerView);
wecandeoSdk.setDebugTextView(debugText);
//기본 컨트롤 뷰사용
wecandeoSdk.setUseController(false);
Expand All @@ -172,7 +169,7 @@ public void onResponse(String response) {
String videoUrl = videoDetailObject.get("videoUrl").getAsString();
wecandeoVideo.setVideoKey(videoUrl);
wecandeoSdk.setWecandeoVideo(wecandeoVideo);
wecandeoSdk.setSimpleExoPlayerView(simpleExoPlayerView);
wecandeoSdk.setPlayerView(playerView);
wecandeoSdk.setDebugTextView(debugText);
//기본 컨트롤 뷰사용
wecandeoSdk.setUseController(false);
Expand Down Expand Up @@ -249,8 +246,8 @@ public void onClick(View view){
break;
case R.id.stop_button :
disableButton(stopButton);
wecandeoSdk.stop();
vodStatistics.sendStatistics(VodStatistics.STOP);
wecandeoSdk.stop();
isPlaying = false;
break;
case R.id.play_button :
Expand Down Expand Up @@ -306,7 +303,10 @@ public void onNothingSelected(AdapterView<?> parent) {}
private void disableButton(Button button){
if(button == retryButton){
for(Button item : buttonList){
item.setEnabled(true);
if(item == playButton)
item.setEnabled(false);
else
item.setEnabled(true);
}
}else{
for(Button item : buttonList){
Expand Down Expand Up @@ -336,22 +336,19 @@ public void onSdkError(SimpleExoPlayer simpleExoPlayer, int i) {}
@Override
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {}

@Override
public void onLoadingChanged(boolean isLoading) {}


@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
public void onPlaybackStateChanged(int playbackState) {
// 영상이 로드되고 준비가 되면 통계 연동 셋팅
if(playbackState == PLAY_ENABLE && wecandeoSdk.getPlayer() != null && isInitVideoInfo){
if(playbackState == Player.STATE_READY && wecandeoSdk.getPlayer() != null && isInitVideoInfo){
isInitVideoInfo = false;
vodStatistics.setWecandeoSdk(wecandeoSdk);
vodStatistics.setDuration(TimeUnit.MILLISECONDS.toSeconds(wecandeoSdk.getPlayer().getDuration()));
vodStatistics.fetchVideoDetail(videoKey);
}

// 영상이 완료되었을 때
if(playWhenReady && playbackState == PLAY_COMPLETE && wecandeoSdk.getPlayer() != null){
if(playbackState == Player.STATE_ENDED && wecandeoSdk.getPlayer() != null){
wecandeoSdk.complete();
vodStatistics.sendStatistics(VodStatistics.STOP);
if(!playButton.isEnabled()){
Expand All @@ -370,10 +367,5 @@ public void onPlayerError(ExoPlaybackException error) {}

@Override
public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {}

@Override
public void onTimelineChanged(Timeline timeline, Object manifest) {}

@Override
public void onPositionDiscontinuity() {}
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ public class StatisticsUrlInfo {
/* VOD Statistics URL Info */
public static final String VIDEO_INFO_URL = "https://api.wecandeo.com/v1/new/player/video.json?k=";
public static final String VIDEO_STATS_INFO_URL = "https://api.wecandeo.com/v1/player/stats/info.json?k=";
public static final String VIDEO_PLAYS_URL = "http://couscous.acs.wecandeo.io/api/videoPlays?data=";
public static final String SECTIONS_URL = "http://couscous.acs.wecandeo.io/api/videoSections?data=";
public static final String CUE_POINT_URL = "http://couscous.acs.wecandeo.io/api/videoCuePoints?data=";
public static final String VIDEO_PLAYS_URL = "https://couscous.acs.wecandeo.io/play/api/videoPlays?data=";
public static final String SECTIONS_URL = "https://couscous.acs.wecandeo.io/video/api/videoSections?data=";
public static final String CUE_POINT_URL = "https://couscous.acs.wecandeo.io/video/api/videoCuePoints?data=";

/* Live Statistics URL Info */
public static final String LIVE_INFO_URL = "https://api.wecandeo.com/live/new/player/info.json?k=";
public static final String LIVE_STATS_INFO_URL = "https://api.wecandeo.com/live/player/stats/info.json?k=";
public static final String LIVE_LOG_URL = "https://couscous.acs.wecandeo.io/api/liveWatches?data=";
public static final String LIVE_LOG_URL = "https://couscous.acs.wecandeo.io/video/api/liveWatches?data=";

}
Loading

0 comments on commit 62ff36b

Please sign in to comment.