├── .gitignore
├── .idea
├── .name
├── codeStyles
│ └── Project.xml
├── dictionaries
│ └── owonseog.xml
├── gradle.xml
├── misc.xml
├── render.experimental.xml
├── runConfigurations.xml
└── vcs.xml
├── Readme.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── ows
│ │ └── boostcourse
│ │ └── uiplayer
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── ows
│ │ │ └── boostcourse
│ │ │ └── uiplayer
│ │ │ └── MainActivity.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ ├── ic_launcher_background.xml
│ │ └── question2.png
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ └── dialog.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── ows
│ └── boostcourse
│ └── uiplayer
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── iaplayer
├── .gitignore
├── build.gradle
├── consumer-rules.pro
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── ows
│ │ └── boostcourse
│ │ └── iaplayer
│ │ ├── ExampleInstrumentedTest.java
│ │ └── IAPlayerTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── ows
│ │ │ └── boostcourse
│ │ │ └── iaplayer
│ │ │ ├── IAListener.java
│ │ │ ├── IAMeesage.java
│ │ │ ├── IAPlayer.java
│ │ │ ├── PlayerListener.java
│ │ │ ├── ServiceListener.java
│ │ │ ├── SimpleIAPlayer.java
│ │ │ └── SocketService.java
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── ows
│ └── boostcourse
│ └── iaplayer
│ └── ExampleUnitTest.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | UIPlayer
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | xmlns:android
14 |
15 | ^$
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | xmlns:.*
25 |
26 | ^$
27 |
28 |
29 | BY_NAME
30 |
31 |
32 |
33 |
34 |
35 |
36 | .*:id
37 |
38 | http://schemas.android.com/apk/res/android
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | .*:name
48 |
49 | http://schemas.android.com/apk/res/android
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | name
59 |
60 | ^$
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | style
70 |
71 | ^$
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | .*
81 |
82 | ^$
83 |
84 |
85 | BY_NAME
86 |
87 |
88 |
89 |
90 |
91 |
92 | .*
93 |
94 | http://schemas.android.com/apk/res/android
95 |
96 |
97 | ANDROID_ATTRIBUTE_ORDER
98 |
99 |
100 |
101 |
102 |
103 |
104 | .*
105 |
106 | .*
107 |
108 |
109 | BY_NAME
110 |
111 |
112 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/.idea/dictionaries/owonseog.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
24 |
25 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Android
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/.idea/render.experimental.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Readme.md:
--------------------------------------------------------------------------------
1 | ## IAPlayer
2 |
3 | IAPlayer is a media player that interacts with users. You can make your video's story change with your response. IAPlayer has all the capabilites of the Exoplayer and communicates with the server through SocketService. It was UIPlayer at first, but I changed it to IAPlayer because it could cause confusion with the user interface.
4 |
5 |
6 |
7 | ### Project Scenario
8 |
9 | 
10 |
11 |
12 | 1. Start IAPlayer
13 | 2. Foreground : specfic movie playback
14 | Background : server connet (socket server)
15 | 3. Wait Event
16 | 4. Require a user to response when an event occurs
17 | 5. Send a user's response to server
18 | 6. server socket change movie
19 |
20 | ### Component Design
21 |
22 | 
23 |
24 |
25 | - IAPlayer : Interaction Player
26 | IAPlayer has mainPlayer and playerlist.
27 |
28 | mainPlayer is SimpleIAPlayer who is in charge of the actual player
29 |
30 | playerlist is a temporary storage player list to solve buffering problems
31 |
32 | - SimpleIAPlayer : Exoplayer child and has customizing player.EventListener
33 |
34 | - SocketService : connect to server sockets in the background
35 |
36 | - IAMessage : IAMessage has event-related information ex) EventTime, url, title...
37 |
38 | ### Using IAPlayer
39 |
40 | The same environment for using Exoplayer
41 |
42 | ### Step 1
43 |
44 | Create IAPlayer instance.
45 |
46 | ```
47 | // Component that set the network bandwidth
48 | DefaultBandwidthMeter defaultBandwidthMeter = new DefaultBandwidthMeter.Builder().build();
49 |
50 | // AdaptiveTrackSelection Component
51 | AdaptiveTrackSelection.Factory adaptiveTrackSelection = new AdaptiveTrackSelection.Factory(defaultBandwidthMeter);
52 |
53 | // Set default track section
54 | DefaultTrackSelector defaultTrackSelector = new DefaultTrackSelector(adaptiveTrackSelection);
55 |
56 | // Control media buffering
57 | LoadControl loadControl = new DefaultLoadControl();
58 |
59 | // Component acting as rendering
60 | DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(this);
61 |
62 | // Create IAPlayer
63 | iaPlayer = new IAPlayer(renderersFactory,defaultTrackSelector,loadControl,null);
64 | binding = DataBindingUtil.setContentView(this,R.layout.activity_main);
65 | binding.exoplayer.setPlayer(iaPlayer.getIAPlayer());
66 | ```
67 |
68 | ### Step 2
69 |
70 | Prepare media sample and set host and port.
71 |
72 | ```
73 | // Media sample uri
74 | Uri uri = Uri.parse(URL);
75 |
76 | // Component for requesting data (HTTP, uri ..)
77 | DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this,"example-test"));
78 |
79 | // Media sample sources required for http live streaming
80 | HlsMediaSource hlsMediaSource = new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(uri);
81 | iaPlayer.setDataSourceFactory(dataSourceFactory);
82 | iaPlayer.setHostAndPort("localhost",5001);
83 | ```
84 |
85 | ### Step3
86 |
87 | Customize IAListener and connect SocketService.
88 |
89 | ```
90 | // IAPlayer prepare
91 | iaPlayer.prepare(
92 |
93 | // Customizeing IAListener
94 | new IAListener() {
95 |
96 | // Callback method invoked when an event occurs.
97 | @Override
98 | public void onConnet() {
99 |
100 | }
101 |
102 | // Callback method invoked when a user responses.
103 | @Override
104 | public void onUserSelect(final IAMeesage iaMeesage) {
105 |
106 |
107 | }
108 | },
109 | hlsMediaSource
110 | );
111 | iaPlayer.connect(this, SocketService.class);
112 | ```
113 |
114 | You can also customize the socketservice that is responsible for server communication.
115 |
116 | ### End
117 |
118 | I'm still junior developer. I'm going to grow into an Android developer. I know is a way that not right to be inefficient and library iaplayer But I have made based on knowledge of the library. Thanks very much a drip if you would give the advice you gave me an efficient development. ( ex) pull request ..)
119 |
120 | Thank you for reading my readme.
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 29
5 | buildToolsVersion "29.0.0"
6 | defaultConfig {
7 | applicationId "ows.boostcourse.uiplayer"
8 | minSdkVersion 15
9 | targetSdkVersion 29
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | dataBinding{
21 | enabled = true
22 | }
23 | }
24 |
25 | dependencies {
26 | implementation fileTree(dir: 'libs', include: ['*.jar'])
27 | implementation 'androidx.appcompat:appcompat:1.0.2'
28 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
29 | implementation project(':iaplayer')
30 | implementation 'com.google.android.exoplayer:exoplayer:2.8.0'
31 | testImplementation 'junit:junit:4.12'
32 | androidTestImplementation 'androidx.test.ext:junit:1.1.0'
33 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
34 | }
35 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/ows/boostcourse/uiplayer/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package ows.boostcourse.uiplayer;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.platform.app.InstrumentationRegistry;
6 | import androidx.test.ext.junit.runners.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24 |
25 | assertEquals("ows.boostcourse.uiplayer", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/ows/boostcourse/uiplayer/MainActivity.java:
--------------------------------------------------------------------------------
1 | package ows.boostcourse.uiplayer;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 | import androidx.databinding.DataBindingUtil;
5 |
6 | import android.app.AlertDialog;
7 | import android.app.Dialog;
8 | import android.content.Context;
9 | import android.content.DialogInterface;
10 | import android.net.Uri;
11 | import android.os.Bundle;
12 | import android.view.LayoutInflater;
13 | import android.view.View;
14 | import android.view.WindowManager;
15 | import android.widget.Button;
16 |
17 | import com.google.android.exoplayer2.DefaultLoadControl;
18 | import com.google.android.exoplayer2.DefaultRenderersFactory;
19 | import com.google.android.exoplayer2.LoadControl;
20 | import com.google.android.exoplayer2.source.hls.HlsMediaSource;
21 | import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;
22 | import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
23 | import com.google.android.exoplayer2.upstream.DataSource;
24 | import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
25 | import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
26 | import com.google.android.exoplayer2.util.Util;
27 |
28 | import ows.boostcourse.uiplayer.databinding.ActivityMainBinding;
29 | import ows.boostcourse.iaplayer.IAPlayer;
30 | import ows.boostcourse.iaplayer.IAListener;
31 | import ows.boostcourse.iaplayer.IAMeesage;
32 | import ows.boostcourse.iaplayer.SocketService;
33 |
34 | public class MainActivity extends AppCompatActivity{
35 |
36 | public static final String URL = "https://multiplatform-f.akamaihd.net/i/multi/will/bunny/big_buck_bunny_,640x360_400,640x360_700,640x360_1000,950x540_1500,.f4v.csmil/master.m3u8";
37 | ActivityMainBinding binding;
38 |
39 | IAPlayer iaPlayer; // 실행할 IAPlayer
40 |
41 | @Override
42 | protected void onCreate(Bundle savedInstanceState) {
43 | super.onCreate(savedInstanceState);
44 | setContentView(R.layout.activity_main);
45 |
46 | // Component that set the network bandwidth
47 | DefaultBandwidthMeter defaultBandwidthMeter = new DefaultBandwidthMeter.Builder().build();
48 |
49 | // AdaptiveTrackSelection Component
50 | AdaptiveTrackSelection.Factory adaptiveTrackSelection = new AdaptiveTrackSelection.Factory(defaultBandwidthMeter);
51 |
52 | // Set default track section
53 | DefaultTrackSelector defaultTrackSelector = new DefaultTrackSelector(adaptiveTrackSelection);
54 |
55 | // Control media buffering
56 | LoadControl loadControl = new DefaultLoadControl();
57 |
58 | // Component acting as rendering
59 | DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(this);
60 |
61 | // Create IAPlayer
62 | iaPlayer = new IAPlayer(renderersFactory,defaultTrackSelector,loadControl,null);
63 | binding = DataBindingUtil.setContentView(this,R.layout.activity_main);
64 | binding.exoplayer.setPlayer(iaPlayer.getIAPlayer());
65 |
66 | // Media sample uri
67 | Uri uri = Uri.parse(URL);
68 |
69 | // Component for requesting data (HTTP, uri ..)
70 | DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this,"example-test"));
71 |
72 | // Media sample sources required for http live streaming
73 | HlsMediaSource hlsMediaSource = new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(uri);
74 | iaPlayer.setDataSourceFactory(dataSourceFactory);
75 | iaPlayer.setHostAndPort("localhost",5001);
76 |
77 | // IAPlayer prepare
78 | iaPlayer.prepare(
79 |
80 | // Customizeing IAListener
81 | new IAListener() {
82 |
83 | // Callback method invoked when an event occurs.
84 | @Override
85 | public void onConnet() {
86 |
87 | }
88 |
89 | // Callback method invoked when a user responses.
90 | @Override
91 | public void onUserSelect(final IAMeesage iaMeesage) {
92 |
93 | final Dialog dialog = new Dialog(MainActivity.this);
94 | View view = getLayoutInflater().inflate(R.layout.dialog,null);
95 |
96 | Button button = view.findViewById(R.id.button);
97 | button.setText(iaMeesage.getTitle()[0]);
98 | button.setOnClickListener(new View.OnClickListener() {
99 | @Override
100 | public void onClick(View v) {
101 | iaPlayer.decidePlayer(0,iaMeesage.getNextId()[0]);
102 | binding.exoplayer.setPlayer(iaPlayer.getIAPlayer());
103 | dialog.dismiss();
104 | }
105 | });
106 |
107 | Button button2 = view.findViewById(R.id.button2);
108 | button2.setText(iaMeesage.getTitle()[1]);
109 | button2.setOnClickListener(new View.OnClickListener() {
110 | @Override
111 | public void onClick(View v) {
112 | iaPlayer.decidePlayer(1,iaMeesage.getNextId()[1]);
113 | binding.exoplayer.setPlayer(iaPlayer.getIAPlayer());
114 | dialog.dismiss();
115 | }
116 | });
117 | dialog.setContentView(view);
118 |
119 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
120 | lp.copyFrom(dialog.getWindow().getAttributes());
121 | lp.width = 1000;
122 | lp.height = 1000;
123 | dialog.getWindow().setAttributes(lp);
124 |
125 | dialog.show();
126 |
127 | }
128 | },
129 | hlsMediaSource
130 | );
131 | iaPlayer.connect(this, SocketService.class);
132 |
133 |
134 | }
135 |
136 | }
137 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/question2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ows3090/UIPlayer/8977e12ed170bbf43ce9c93feaf18b88fbfd18cd/app/src/main/res/drawable/question2.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
20 |
21 |
32 |
33 |
42 |
43 |
52 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ows3090/UIPlayer/8977e12ed170bbf43ce9c93feaf18b88fbfd18cd/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ows3090/UIPlayer/8977e12ed170bbf43ce9c93feaf18b88fbfd18cd/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ows3090/UIPlayer/8977e12ed170bbf43ce9c93feaf18b88fbfd18cd/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ows3090/UIPlayer/8977e12ed170bbf43ce9c93feaf18b88fbfd18cd/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ows3090/UIPlayer/8977e12ed170bbf43ce9c93feaf18b88fbfd18cd/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ows3090/UIPlayer/8977e12ed170bbf43ce9c93feaf18b88fbfd18cd/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ows3090/UIPlayer/8977e12ed170bbf43ce9c93feaf18b88fbfd18cd/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ows3090/UIPlayer/8977e12ed170bbf43ce9c93feaf18b88fbfd18cd/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ows3090/UIPlayer/8977e12ed170bbf43ce9c93feaf18b88fbfd18cd/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ows3090/UIPlayer/8977e12ed170bbf43ce9c93feaf18b88fbfd18cd/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | UIPlayer
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/ows/boostcourse/uiplayer/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package ows.boostcourse.uiplayer;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | google()
6 | jcenter()
7 |
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.5.1'
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | google()
19 | jcenter()
20 |
21 | }
22 | }
23 |
24 | task clean(type: Delete) {
25 | delete rootProject.buildDir
26 | }
27 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 |
21 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ows3090/UIPlayer/8977e12ed170bbf43ce9c93feaf18b88fbfd18cd/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Aug 10 10:57:28 KST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/iaplayer/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/iaplayer/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'jacoco'
3 |
4 | android {
5 | compileSdkVersion 29
6 | buildToolsVersion "29.0.0"
7 |
8 |
9 | defaultConfig {
10 | minSdkVersion 15
11 | targetSdkVersion 29
12 | versionCode 1
13 | versionName "1.0"
14 | multiDexEnabled true
15 |
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | consumerProguardFiles 'consumer-rules.pro'
18 | }
19 |
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
24 | }
25 |
26 | debug{
27 | testCoverageEnabled = true
28 | }
29 | }
30 |
31 | testOptions {
32 | unitTests.returnDefaultValues = true
33 | }
34 | }
35 |
36 | dependencies {
37 | testImplementation 'junit:junit:4.12'
38 | androidTestCompile "org.robolectric:robolectric:3.0-rc1"
39 |
40 | // Required for instrumented tests
41 | androidTestImplementation 'com.android.support:support-annotations:24.0.0'
42 | androidTestImplementation 'com.android.support.test:runner:0.5'
43 |
44 | implementation fileTree(dir: 'libs', include: ['*.jar'])
45 | implementation 'androidx.appcompat:appcompat:1.0.2'
46 | implementation 'com.google.android.exoplayer:exoplayer:2.8.0'
47 | testImplementation 'junit:junit:4.12'
48 | androidTestImplementation 'androidx.test.ext:junit:1.1.0'
49 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
50 | implementation 'org.jetbrains:annotations-java5:15.0'
51 |
52 | }
53 |
54 | apply plugin: 'jacoco'
55 |
56 | jacoco {
57 | reportsDir = file("${buildDir}/reports")
58 | }
59 |
60 | task coverageReport(type: JacocoReport, dependsOn: 'testDevDebugUnitTest') {
61 | group = "Reporting"
62 | description = "Generate Jacoco coverage reports"
63 |
64 | def coverageSourceDirs = ['src/']
65 |
66 | classDirectories = fileTree(
67 | dir: "${buildDir}/intermediates/classes/dev/debug",
68 | excludes: ['**/R.class',
69 | '**/R$*.class',
70 | '**/BuildConfig.*',
71 | '**/Manifest*.*',
72 | 'com/android/**/*.class']
73 | )
74 |
75 | sourceDirectories = files(coverageSourceDirs)
76 | executionData = files("${buildDir}/jacoco/testDevDebugUnitTest.exec")
77 |
78 | reports {
79 | xml.enabled = true
80 | html.enabled = true
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/iaplayer/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ows3090/UIPlayer/8977e12ed170bbf43ce9c93feaf18b88fbfd18cd/iaplayer/consumer-rules.pro
--------------------------------------------------------------------------------
/iaplayer/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/iaplayer/src/androidTest/java/ows/boostcourse/iaplayer/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package ows.boostcourse.iaplayer;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.platform.app.InstrumentationRegistry;
6 | import androidx.test.ext.junit.runners.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24 |
25 | assertEquals("ows.boostcourse.iaplayer.test", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/iaplayer/src/androidTest/java/ows/boostcourse/iaplayer/IAPlayerTest.java:
--------------------------------------------------------------------------------
1 | package ows.boostcourse.iaplayer;
2 |
3 | import android.content.Context;
4 | import android.net.Uri;
5 |
6 | import androidx.test.ext.junit.runners.AndroidJUnit4;
7 | import androidx.test.platform.app.InstrumentationRegistry;
8 |
9 | import com.google.android.exoplayer2.DefaultLoadControl;
10 | import com.google.android.exoplayer2.DefaultRenderersFactory;
11 | import com.google.android.exoplayer2.LoadControl;
12 | import com.google.android.exoplayer2.source.hls.HlsMediaSource;
13 | import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;
14 | import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
15 | import com.google.android.exoplayer2.upstream.DataSource;
16 | import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
17 | import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
18 | import com.google.android.exoplayer2.util.Util;
19 |
20 | import org.junit.Before;
21 | import org.junit.Test;
22 | import org.junit.runner.RunWith;
23 |
24 | import static org.junit.Assert.*;
25 |
26 | @RunWith(AndroidJUnit4.class)
27 | public class IAPlayerTest {
28 |
29 | String URL = "https://multiplatform-f.akamaihd.net/i/multi/will/bunny/big_buck_bunny_,640x360_400,640x360_700,640x360_1000,950x540_1500,.f4v.csmil/master.m3u8";
30 | Context context;
31 | IAPlayer iaPlayer;
32 | SimpleIAPlayer simpleIAPlayer;
33 | IAListener iaListener;
34 | HlsMediaSource hlsMediaSource;
35 |
36 | @Before
37 | public void setUp() throws Exception {
38 | context = InstrumentationRegistry.getInstrumentation().getTargetContext();
39 |
40 | // 네트워크 대역폭을 설정하는 요소
41 | DefaultBandwidthMeter defaultBandwidthMeter = new DefaultBandwidthMeter.Builder().build();
42 |
43 | // 트랙 섹션 중 하나로 적응형 트랙섹션
44 | AdaptiveTrackSelection.Factory adaptiveTrackSelection = new AdaptiveTrackSelection.Factory(defaultBandwidthMeter);
45 |
46 | // 기본 트랙 섹션 설정
47 | DefaultTrackSelector defaultTrackSelector = new DefaultTrackSelector(adaptiveTrackSelection);
48 |
49 | // 미디어 버퍼링을 컨트롤
50 | LoadControl loadControl = new DefaultLoadControl();
51 |
52 | // 미디어 파일 읽고, 디코딩 후 렌더링 요소
53 | DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(context);
54 |
55 | iaPlayer = new IAPlayer(renderersFactory,defaultTrackSelector,loadControl,null);
56 | simpleIAPlayer = new SimpleIAPlayer(renderersFactory,defaultTrackSelector,loadControl,null);
57 | iaListener = new IAListener() {
58 | @Override
59 | public void onConnet() {
60 |
61 | }
62 |
63 | @Override
64 | public void onUserSelect(IAMeesage uiMessage) {
65 |
66 | }
67 | };
68 |
69 | Uri uri = Uri.parse(URL);
70 |
71 | // 데이터를 요청하기 위한 구성요소 (HTTP, uri ..)
72 | DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, Util.getUserAgent(context,"example-test"));
73 |
74 | // HLS에 필요한 미디어 샘플 소스
75 | hlsMediaSource = new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(uri);
76 | }
77 |
78 | @Test
79 | public void getIAPlayer() {
80 | assertEquals(simpleIAPlayer,iaPlayer.getIAPlayer());
81 | }
82 |
83 | @Test
84 | public void connect() {
85 | boolean check = iaPlayer.connect(context,SocketService.class);
86 | assertEquals(false,check);
87 | }
88 |
89 | @Test
90 | public void disconnect() {
91 | boolean check = iaPlayer.disconnect();
92 | assertEquals(false,check);
93 | }
94 |
95 | @Test
96 | public void prepare() {
97 | boolean check = iaPlayer.prepare(iaListener,hlsMediaSource);
98 | assertEquals(true, check);
99 | }
100 |
101 | @Test
102 | public void play() {
103 | boolean check = iaPlayer.play("localhost",5001);
104 | assertEquals(true,check);
105 | }
106 |
107 | @Test
108 | public void decidePlayer() {
109 | assertEquals(4,2+1);
110 | }
111 | }
--------------------------------------------------------------------------------
/iaplayer/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/iaplayer/src/main/java/ows/boostcourse/iaplayer/IAListener.java:
--------------------------------------------------------------------------------
1 | package ows.boostcourse.iaplayer;
2 |
3 | public interface IAListener {
4 |
5 | void onConnet();
6 | void onUserSelect(IAMeesage uiMessage);
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/iaplayer/src/main/java/ows/boostcourse/iaplayer/IAMeesage.java:
--------------------------------------------------------------------------------
1 | package ows.boostcourse.iaplayer;
2 |
3 | import java.io.Serializable;
4 |
5 | public class IAMeesage implements Serializable {
6 |
7 | private final int MAX_COUNT=3;
8 | private long eventTime;
9 | private int urlCount;
10 | private String[] url;
11 | private String[] title;
12 | private int[] nextId;
13 |
14 | public IAMeesage(){
15 | eventTime = 10000000;
16 | urlCount = MAX_COUNT;
17 | url = new String[MAX_COUNT];
18 | title = new String[MAX_COUNT];
19 | nextId = new int[MAX_COUNT];
20 | }
21 |
22 | public IAMeesage(long eventTime, int urlCount, String[] url,String[] title, int[] nextId) {
23 | this.eventTime = eventTime;
24 | this.urlCount = urlCount;
25 | this.url = url;
26 | this.title = title;
27 | this.nextId = nextId;
28 | }
29 |
30 | public void setEventTime(long eventTime) {
31 | this.eventTime = eventTime;
32 | }
33 |
34 | public void setUrlCount(int urlCount) {
35 | this.urlCount = urlCount;
36 | }
37 |
38 | public void setUrl(String[] url) {
39 | this.url = url;
40 | }
41 |
42 | public void setTitle(String[] title) {
43 | this.title = title;
44 | }
45 |
46 | public void setNextId(int[] nextId) {
47 | this.nextId = nextId;
48 | }
49 |
50 | public long getEventTime() {
51 | return eventTime;
52 | }
53 |
54 | public int getUrlCount() {
55 | return urlCount;
56 | }
57 |
58 | public String[] getUrl() {
59 | return url;
60 | }
61 |
62 | public String[] getTitle() {
63 | return title;
64 | }
65 |
66 | public int[] getNextId() {
67 | return nextId;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/iaplayer/src/main/java/ows/boostcourse/iaplayer/IAPlayer.java:
--------------------------------------------------------------------------------
1 | package ows.boostcourse.iaplayer;
2 |
3 | import android.content.ComponentName;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.content.ServiceConnection;
7 | import android.net.Uri;
8 | import android.os.Handler;
9 | import android.os.IBinder;
10 | import android.util.Log;
11 |
12 | import androidx.annotation.Nullable;
13 |
14 | import com.google.android.exoplayer2.ExoPlaybackException;
15 | import com.google.android.exoplayer2.LoadControl;
16 | import com.google.android.exoplayer2.PlaybackParameters;
17 | import com.google.android.exoplayer2.Player;
18 | import com.google.android.exoplayer2.RenderersFactory;
19 | import com.google.android.exoplayer2.Timeline;
20 | import com.google.android.exoplayer2.analytics.AnalyticsCollector;
21 | import com.google.android.exoplayer2.drm.DrmSessionManager;
22 | import com.google.android.exoplayer2.drm.FrameworkMediaCrypto;
23 | import com.google.android.exoplayer2.source.TrackGroupArray;
24 | import com.google.android.exoplayer2.source.hls.HlsMediaSource;
25 | import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
26 | import com.google.android.exoplayer2.trackselection.TrackSelector;
27 | import com.google.android.exoplayer2.upstream.DataSource;
28 | import com.google.android.exoplayer2.util.Clock;
29 |
30 |
31 | public class IAPlayer {
32 |
33 | private final static String TAG = "TAG";
34 | private final static String DEFAULT_HOST = "localhost";
35 | private final static int DEFAULT_PORT = 5001;
36 |
37 | private boolean isChanged; // 스트리밍이 바뀌었는지 확인 여부
38 | private boolean isStart; // 스트리밍 시작했는지 확인 여부
39 | private boolean playerNum; // 스트리밍 변화 횟수만큼
40 |
41 | private int MAX_PLAYERCOUNT = 3; // 스트리밍 분기될 임시 Player 최대 갯수
42 | private int currentPlayerCount; // 스트리밍 분기될 임시 Player 갯수
43 | private int nextId;
44 | private SimpleIAPlayer mainPlayer; // 현재 실행될 Player
45 | private SimpleIAPlayer[] playerList = new SimpleIAPlayer[MAX_PLAYERCOUNT*2]; // 스트리밍 분기를 위한 임시 Player
46 |
47 | private DataSource.Factory dataSourceFactory; // MediaSource를 만들기 위한 DataSource.Factory
48 | private Context context; // Context 정보
49 | private Class> name; // 클래스 명
50 |
51 | private String host; // 서버소켓과 연결하기 위한 Host 정보
52 | private int port; // 서버소켓과 연결하기 위한 Port 정보
53 | private SocketService socketService; // 소켓 통신할 서비스
54 | private boolean isService;
55 |
56 | // 비동기를 위한 핸들러, Runnable 객체
57 | private Handler playerHandler = new Handler();
58 | private Runnable playerRunnable = new Runnable() {
59 | @Override
60 | public void run() {
61 | sendPlayTime();
62 | }
63 | };
64 |
65 | // 서비스 바인딩에 필요한 서비스 Connection 객체
66 | private ServiceConnection conn = new ServiceConnection() {
67 | @Override
68 | public void onServiceConnected(ComponentName name, IBinder service) {
69 | SocketService.LocalBinder localBinder = (SocketService.LocalBinder) service;
70 | socketService = localBinder.getService();
71 | isService = true;
72 | iaListener.onConnet();
73 | }
74 |
75 | @Override
76 | public void onServiceDisconnected(ComponentName name) {
77 | isService = false;
78 | }
79 | };
80 |
81 | // User와 통신하기 위한 리스너
82 | private IAListener iaListener;
83 |
84 | // UIPlayer와 UIService의 상호작용 이벤트 리스너
85 | private ServiceListener serviceListener = new ServiceListener() {
86 |
87 | @Override
88 | public void onPreceed() {
89 | serviceStop();
90 | serviceRequest();
91 | }
92 |
93 | @Override
94 | public void onGetEvent(final IAMeesage iaMeesage) {
95 | currentPlayerCount = iaMeesage.getUrlCount();
96 | playerNum = !playerNum;
97 | isChanged = true;
98 |
99 | for(int i=0;i drmSessionManager) {
209 | this.isChanged = false;
210 | this.isStart = false;
211 | this.isService = false;
212 | this.playerNum = false;
213 | this.currentPlayerCount = MAX_PLAYERCOUNT;
214 | this.nextId = 0;
215 | this.host = DEFAULT_HOST;
216 | this.port = DEFAULT_PORT;
217 | mainPlayer = new SimpleIAPlayer(renderersFactory,trackSelector,loadControl,null);
218 | for(int i = 0; i< MAX_PLAYERCOUNT*2; i++){
219 | playerList[i] = new SimpleIAPlayer(renderersFactory,trackSelector,loadControl,null);
220 | }
221 | }
222 |
223 | public IAPlayer(RenderersFactory renderersFactory, TrackSelector trackSelector, LoadControl loadControl, @Nullable DrmSessionManager drmSessionManager, AnalyticsCollector.Factory analyticsCollectorFactory) {
224 | this.isChanged = false;
225 | this.isStart = false;
226 | this.isService = false;
227 | this.playerNum = false;
228 | this.currentPlayerCount = MAX_PLAYERCOUNT;
229 | this.nextId = 0;
230 | this.host = DEFAULT_HOST;
231 | this.port = DEFAULT_PORT;
232 | mainPlayer = new SimpleIAPlayer(renderersFactory,trackSelector,loadControl,null);
233 | for(int i = 0; i< MAX_PLAYERCOUNT*2; i++){
234 | playerList[i] = new SimpleIAPlayer(renderersFactory,trackSelector,loadControl,null);
235 | }
236 | }
237 |
238 | public IAPlayer(RenderersFactory renderersFactory, TrackSelector trackSelector, LoadControl loadControl, @Nullable DrmSessionManager drmSessionManager, AnalyticsCollector.Factory analyticsCollectorFactory, Clock clock) {
239 | this.isChanged = false;
240 | this.isStart = false;
241 | this.isService = false;
242 | this.playerNum = false;
243 | this.currentPlayerCount = MAX_PLAYERCOUNT;
244 | this.nextId = 0;
245 | this.host = DEFAULT_HOST;
246 | this.port = DEFAULT_PORT;
247 | mainPlayer = new SimpleIAPlayer(renderersFactory,trackSelector,loadControl,null);
248 | for(int i = 0; i< MAX_PLAYERCOUNT*2; i++){
249 | playerList[i] = new SimpleIAPlayer(renderersFactory,trackSelector,loadControl,null);
250 | }
251 | }
252 |
253 | // mainPlayer의 get 함수
254 | public SimpleIAPlayer getIAPlayer(){
255 | return mainPlayer;
256 | }
257 |
258 | // 서비스와 connect하는 함수
259 | public boolean connect(Context context, Class> name){
260 | this.context = context;
261 | this.name = name;
262 | Intent intent = new Intent(context,name);
263 | return context.bindService(intent,conn,context.BIND_AUTO_CREATE);
264 | }
265 |
266 | // 서비스와 disconnect하는 함수
267 | public boolean disconnect(){
268 | context.unbindService(conn);
269 | return isService;
270 | }
271 |
272 | // Uri을 Mediasource로 바꾸기 위한 DataSource.Factory 지정
273 | public void setDataSourceFactory(DataSource.Factory dataSourceFactory){
274 | this.dataSourceFactory = dataSourceFactory;
275 | }
276 |
277 | // 소켓 통신을 위한 Host, Port정보 설정
278 | public void setHostAndPort(String host, int port){
279 | this.host = host;
280 | this.port = port;
281 | }
282 |
283 | // 해당 미디어 소스 mainPlayer에 준비
284 | public boolean prepare(IAListener uiListener, HlsMediaSource hlsmediaSource) {
285 | this.iaListener = uiListener;
286 | mainPlayer.prepare(hlsmediaSource);
287 | mainPlayer.addListener(eventListener);
288 | return mainPlayer.getPlayWhenReady();
289 | }
290 |
291 | // 플레이어 재생
292 | public boolean play(String host, int port){
293 | Log.d(TAG,"play");
294 | socketService.init(serviceListener,host,port);
295 | mainPlayer.play();
296 | return mainPlayer.getPlaybackState()==Player.STATE_READY;
297 | }
298 |
299 | // 서버소켓 연결 (시작 시, 다음 스트리밍 분기 확인)
300 | private void serviceStart(){
301 | Log.d(TAG,"serviceStart");
302 | isStart = true;
303 | socketService.getIATime(nextId);
304 | }
305 |
306 | // 서버소켓에 요청 핸들러에 Runnable객체 전달
307 | private void serviceRequest(){
308 | playerHandler.postDelayed(playerRunnable,1000);
309 | }
310 |
311 | // 서버소켓 연결 종료
312 | private void serviceStop(){
313 | playerHandler.removeCallbacks(playerRunnable);
314 | }
315 |
316 | // 서버소켓에 플레이저 재생 시간 전송
317 | private void sendPlayTime(){
318 | socketService.sendToSocket((mainPlayer.getCurrentPosition()/1000)*1000);
319 | }
320 |
321 | // 사용자 응답 결과를 바탕으로 새로운 플레이어 지정 후 실행
322 | public void decidePlayer(int position,int nextId){
323 | Log.d(TAG,"decidePlayer");
324 | this.nextId = nextId;
325 | if(playerNum){
326 | mainPlayer = playerList[position+MAX_PLAYERCOUNT];
327 | }else{
328 |
329 | mainPlayer = playerList[position];
330 | }
331 | mainPlayer.addListener(eventListener);
332 | play(host,port);
333 | }
334 |
335 |
336 | }
337 |
--------------------------------------------------------------------------------
/iaplayer/src/main/java/ows/boostcourse/iaplayer/PlayerListener.java:
--------------------------------------------------------------------------------
1 | package ows.boostcourse.iaplayer;
2 |
3 | public interface PlayerListener {
4 |
5 | void onPlayerStart();
6 | void onRequestMeesage();
7 | void onRequestTime();
8 | void onStop();
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/iaplayer/src/main/java/ows/boostcourse/iaplayer/ServiceListener.java:
--------------------------------------------------------------------------------
1 | package ows.boostcourse.iaplayer;
2 |
3 | public interface ServiceListener {
4 |
5 | void onGetEvent(IAMeesage uiMessage);
6 | void onPreceed();
7 | void onResponse(IAMeesage uiMessage);
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/iaplayer/src/main/java/ows/boostcourse/iaplayer/SimpleIAPlayer.java:
--------------------------------------------------------------------------------
1 | package ows.boostcourse.iaplayer;
2 |
3 | import android.util.Log;
4 |
5 | import androidx.annotation.Nullable;
6 |
7 | import com.google.android.exoplayer2.ExoPlaybackException;
8 | import com.google.android.exoplayer2.LoadControl;
9 | import com.google.android.exoplayer2.PlaybackParameters;
10 | import com.google.android.exoplayer2.Player;
11 | import com.google.android.exoplayer2.RenderersFactory;
12 | import com.google.android.exoplayer2.SimpleExoPlayer;
13 | import com.google.android.exoplayer2.Timeline;
14 | import com.google.android.exoplayer2.analytics.AnalyticsCollector;
15 | import com.google.android.exoplayer2.drm.DrmSessionManager;
16 | import com.google.android.exoplayer2.drm.FrameworkMediaCrypto;
17 | import com.google.android.exoplayer2.source.TrackGroupArray;
18 | import com.google.android.exoplayer2.source.hls.HlsMediaSource;
19 | import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
20 | import com.google.android.exoplayer2.trackselection.TrackSelector;
21 | import com.google.android.exoplayer2.util.Clock;
22 |
23 | public class SimpleIAPlayer extends SimpleExoPlayer{
24 |
25 | public SimpleIAPlayer(RenderersFactory renderersFactory, TrackSelector trackSelector, LoadControl loadControl, @Nullable DrmSessionManager drmSessionManager) {
26 | super(renderersFactory, trackSelector, loadControl, drmSessionManager);
27 | }
28 |
29 | public SimpleIAPlayer(RenderersFactory renderersFactory, TrackSelector trackSelector, LoadControl loadControl, @Nullable DrmSessionManager drmSessionManager, AnalyticsCollector.Factory analyticsCollectorFactory) {
30 | super(renderersFactory, trackSelector, loadControl, drmSessionManager, analyticsCollectorFactory);
31 | }
32 |
33 | public SimpleIAPlayer(RenderersFactory renderersFactory, TrackSelector trackSelector, LoadControl loadControl, @Nullable DrmSessionManager drmSessionManager, AnalyticsCollector.Factory analyticsCollectorFactory, Clock clock) {
34 | super(renderersFactory, trackSelector, loadControl, drmSessionManager, analyticsCollectorFactory, clock);
35 | }
36 |
37 | public void prepare(HlsMediaSource hlsmediaSource) {
38 | super.prepare(hlsmediaSource);
39 | }
40 |
41 | public void play() {
42 | setPlayWhenReady(true);
43 | }
44 |
45 | public void stop() {
46 | setPlayWhenReady(false);
47 | }
48 |
49 | }
50 |
51 |
--------------------------------------------------------------------------------
/iaplayer/src/main/java/ows/boostcourse/iaplayer/SocketService.java:
--------------------------------------------------------------------------------
1 | package ows.boostcourse.iaplayer;
2 |
3 | import android.app.Service;
4 | import android.content.Intent;
5 | import android.os.Binder;
6 | import android.os.IBinder;
7 | import android.util.Log;
8 |
9 | import java.io.ObjectInputStream;
10 | import java.io.ObjectOutputStream;
11 | import java.net.Socket;
12 |
13 | public class SocketService extends Service {
14 |
15 | private final static String TAG = "TAG";
16 | private static final String DEFAULT_HOST = "localhost"; // DEFAULT HOST, PORT 정보
17 | private static final int DEFAULT_PORT = 5001;
18 |
19 | private String host; // HOST 정보
20 | private int port; // PORT 정보
21 |
22 | private ServiceListener serviceListener; // UIPlayer와 통신하기 위한 리스너
23 | private IAMeesage iaMeesage; // 소켓통신 후 받게 되는 정보
24 |
25 | // 서비스 바인딩 완료시 반환되는 바인더 클래스
26 | class LocalBinder extends Binder{
27 | SocketService getService(){
28 | return SocketService.this;
29 | }
30 | }
31 |
32 | // LocalBinder의 인스턴스
33 | private final IBinder mbinder = new LocalBinder();
34 |
35 | // 생성자
36 | public SocketService() {
37 | host = DEFAULT_HOST;
38 | port = DEFAULT_PORT;
39 | }
40 |
41 | @Override
42 | public void onCreate() {
43 | super.onCreate();
44 | }
45 |
46 | @Override
47 | public IBinder onBind(Intent intent) {
48 | return mbinder;
49 | }
50 |
51 | @Override
52 | public void onDestroy() {
53 | super.onDestroy();
54 | }
55 |
56 | // 서비스 통신하기 위한 기본 설정
57 | public void init(ServiceListener serviceListener, String host, int port){
58 | iaMeesage = new IAMeesage();
59 | this.serviceListener = serviceListener;
60 | this.host = host;
61 | this.port = port;
62 | }
63 |
64 | // interaction 정보 (IAMeesage)를 얻기 위해 서버소켓과 통신
65 | public void getIATime(final int nextId){
66 | new Thread(new Runnable() {
67 | @Override
68 | public void run() {
69 | try{
70 | Socket socket = new Socket(host,port);
71 |
72 | ObjectOutputStream outputStream = new ObjectOutputStream(socket.getOutputStream());
73 | outputStream.writeObject(nextId);
74 | outputStream.flush();
75 |
76 | ObjectInputStream inputStream = new ObjectInputStream(socket.getInputStream());
77 | long eventTime = (long)inputStream.readObject();
78 | int urlCount = (int)inputStream.readObject();
79 | String[] url = (String[])inputStream.readObject();
80 | String[] title = (String[])inputStream.readObject();
81 | int[] nextId = (int[])inputStream.readObject();
82 |
83 | Log.d(TAG,eventTime + ", "+urlCount+", "+url[0]+", "+url[1]);
84 | Log.d(TAG,title[0]+", "+title[1]+", "+nextId[0]+", "+nextId[1]);
85 | iaMeesage.setEventTime(eventTime);
86 | iaMeesage.setUrlCount(urlCount);
87 | iaMeesage.setUrl(url);
88 | iaMeesage.setTitle(title);
89 | iaMeesage.setNextId(nextId);
90 |
91 | serviceListener.onGetEvent(iaMeesage);
92 |
93 | }catch (Exception e){
94 | e.printStackTrace();
95 | }
96 | }
97 | }).start();
98 | }
99 |
100 | public void sendToSocket(long time){
101 | Log.d(TAG,"connect is "+time);
102 | if(time == iaMeesage.getEventTime()){
103 | serviceListener.onResponse(iaMeesage);
104 | }
105 | // else if(time == iaMeesage.getEventTime()-2000){
106 | // Log.d(TAG,"prepare sample streaming");
107 | //
108 | // serviceListener.onPreceed();
109 | // }
110 | else{
111 | serviceListener.onPreceed();
112 | }
113 | }
114 |
115 |
116 | }
117 |
--------------------------------------------------------------------------------
/iaplayer/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | IAPlayer
3 |
4 |
--------------------------------------------------------------------------------
/iaplayer/src/test/java/ows/boostcourse/iaplayer/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package ows.boostcourse.iaplayer;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 |
18 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':iaplayer'
2 | rootProject.name='UIPlayer'
3 |
--------------------------------------------------------------------------------