├── app
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── drawable-hdpi
│ │ │ ├── sintel_poster.png
│ │ │ ├── ic_action_play_over_video.png
│ │ │ ├── ic_action_pause_over_video.png
│ │ │ ├── ic_action_play_over_video_pressed.png
│ │ │ └── ic_action_pause_over_video_pressed.png
│ │ ├── drawable-mdpi
│ │ │ ├── sintel_poster.png
│ │ │ ├── ic_action_play_over_video.png
│ │ │ ├── ic_action_pause_over_video.png
│ │ │ ├── ic_action_play_over_video_pressed.png
│ │ │ └── ic_action_pause_over_video_pressed.png
│ │ ├── values
│ │ │ ├── integers.xml
│ │ │ ├── dimens.xml
│ │ │ ├── styles.xml
│ │ │ └── strings.xml
│ │ ├── drawable-xhdpi
│ │ │ ├── sintel_poster.png
│ │ │ ├── ic_action_pause_over_video.png
│ │ │ ├── ic_action_play_over_video.png
│ │ │ ├── ic_action_pause_over_video_pressed.png
│ │ │ └── ic_action_play_over_video_pressed.png
│ │ ├── drawable-xxhdpi
│ │ │ ├── sintel_poster.png
│ │ │ ├── ic_action_pause_over_video.png
│ │ │ ├── ic_action_play_over_video.png
│ │ │ ├── ic_action_play_over_video_pressed.png
│ │ │ └── ic_action_pause_over_video_pressed.png
│ │ ├── values-sw600dp
│ │ │ └── dimens.xml
│ │ ├── drawable
│ │ │ ├── ic_action_play.xml
│ │ │ └── ic_action_play_pause.xml
│ │ └── layout
│ │ │ ├── video_player.xml
│ │ │ ├── activity_main.xml
│ │ │ └── video_controls.xml
│ │ ├── java
│ │ └── com
│ │ │ └── doubleencore
│ │ │ └── mpatterson
│ │ │ ├── interfaces
│ │ │ ├── IEndedListener.java
│ │ │ ├── IControlsListener.java
│ │ │ └── IPlayerListener.java
│ │ │ ├── MainActivity.java
│ │ │ ├── controls
│ │ │ ├── ControlsContainer.java
│ │ │ └── VideoControlsView.java
│ │ │ └── exoplayer
│ │ │ ├── ExoPlayerActivity.java
│ │ │ ├── VideoPlayerView.java
│ │ │ ├── AbsVideoPlayerImpl.java
│ │ │ ├── HlsRendererBuilder.java
│ │ │ └── AbsVideoPlayer.java
│ │ └── AndroidManifest.xml
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mpatt3970/HlsExoPlayerDemo/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | local.properties
2 | .DS_Store
3 | .gradle
4 | .idea
5 | *.iml
6 | out
7 | bin
8 | build
9 | target
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/sintel_poster.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mpatt3970/HlsExoPlayerDemo/HEAD/app/src/main/res/drawable-hdpi/sintel_poster.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/sintel_poster.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mpatt3970/HlsExoPlayerDemo/HEAD/app/src/main/res/drawable-mdpi/sintel_poster.png
--------------------------------------------------------------------------------
/app/src/main/res/values/integers.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 500
4 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/sintel_poster.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mpatt3970/HlsExoPlayerDemo/HEAD/app/src/main/res/drawable-xhdpi/sintel_poster.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/sintel_poster.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mpatt3970/HlsExoPlayerDemo/HEAD/app/src/main/res/drawable-xxhdpi/sintel_poster.png
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 96dp
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values-sw600dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 144dp
4 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_action_play_over_video.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mpatt3970/HlsExoPlayerDemo/HEAD/app/src/main/res/drawable-hdpi/ic_action_play_over_video.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_action_play_over_video.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mpatt3970/HlsExoPlayerDemo/HEAD/app/src/main/res/drawable-mdpi/ic_action_play_over_video.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_action_pause_over_video.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mpatt3970/HlsExoPlayerDemo/HEAD/app/src/main/res/drawable-hdpi/ic_action_pause_over_video.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_action_pause_over_video.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mpatt3970/HlsExoPlayerDemo/HEAD/app/src/main/res/drawable-mdpi/ic_action_pause_over_video.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_action_pause_over_video.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mpatt3970/HlsExoPlayerDemo/HEAD/app/src/main/res/drawable-xhdpi/ic_action_pause_over_video.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_action_play_over_video.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mpatt3970/HlsExoPlayerDemo/HEAD/app/src/main/res/drawable-xhdpi/ic_action_play_over_video.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_action_pause_over_video.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mpatt3970/HlsExoPlayerDemo/HEAD/app/src/main/res/drawable-xxhdpi/ic_action_pause_over_video.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_action_play_over_video.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mpatt3970/HlsExoPlayerDemo/HEAD/app/src/main/res/drawable-xxhdpi/ic_action_play_over_video.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_action_play_over_video_pressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mpatt3970/HlsExoPlayerDemo/HEAD/app/src/main/res/drawable-hdpi/ic_action_play_over_video_pressed.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_action_play_over_video_pressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mpatt3970/HlsExoPlayerDemo/HEAD/app/src/main/res/drawable-mdpi/ic_action_play_over_video_pressed.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_action_pause_over_video_pressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mpatt3970/HlsExoPlayerDemo/HEAD/app/src/main/res/drawable-hdpi/ic_action_pause_over_video_pressed.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_action_pause_over_video_pressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mpatt3970/HlsExoPlayerDemo/HEAD/app/src/main/res/drawable-mdpi/ic_action_pause_over_video_pressed.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_action_pause_over_video_pressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mpatt3970/HlsExoPlayerDemo/HEAD/app/src/main/res/drawable-xhdpi/ic_action_pause_over_video_pressed.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_action_play_over_video_pressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mpatt3970/HlsExoPlayerDemo/HEAD/app/src/main/res/drawable-xhdpi/ic_action_play_over_video_pressed.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_action_play_over_video_pressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mpatt3970/HlsExoPlayerDemo/HEAD/app/src/main/res/drawable-xxhdpi/ic_action_play_over_video_pressed.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_action_pause_over_video_pressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mpatt3970/HlsExoPlayerDemo/HEAD/app/src/main/res/drawable-xxhdpi/ic_action_pause_over_video_pressed.png
--------------------------------------------------------------------------------
/app/src/main/java/com/doubleencore/mpatterson/interfaces/IEndedListener.java:
--------------------------------------------------------------------------------
1 | package com.doubleencore.mpatterson.interfaces;
2 |
3 | /**
4 | * Created by michael on 11/27/15.
5 | */
6 | public interface IEndedListener {
7 |
8 | void onEnded();
9 | }
10 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Sep 02 18:10:31 MDT 2015
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-2.4-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Demo Video Player
4 | http://walterebert.com/playground/video/hls/sintel-trailer.m3u8
5 | Unfortunately, an error occurred during playback.
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_action_play.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/java/com/doubleencore/mpatterson/interfaces/IControlsListener.java:
--------------------------------------------------------------------------------
1 | package com.doubleencore.mpatterson.interfaces;
2 |
3 | /**
4 | * Created by michael on 11/27/15.
5 | */
6 | public interface IControlsListener {
7 |
8 | void onPause();
9 | void onPlay();
10 | void onSeekTo(float percentComplete);
11 | void onControlsHidden();
12 | void onControlsShown();
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/doubleencore/mpatterson/interfaces/IPlayerListener.java:
--------------------------------------------------------------------------------
1 | package com.doubleencore.mpatterson.interfaces;
2 |
3 | /**
4 | * Created by michael on 11/27/15.
5 | */
6 | public interface IPlayerListener {
7 |
8 | void onBufferingStart();
9 | void onBufferingComplete();
10 | void onSetDuration(long durationMs);
11 | void onUpdateProgress(float percentComplete);
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_action_play_pause.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/michael/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 22
5 | buildToolsVersion "23.0.0"
6 |
7 | defaultConfig {
8 | applicationId "com.doubleencore.mpatterson.hlsexoplayer"
9 | minSdkVersion 16
10 | targetSdkVersion 22
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | compile 'com.android.support:appcompat-v7:22.2.1'
25 | compile 'com.google.android.exoplayer:exoplayer:r1.5.6'
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/video_player.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
19 |
20 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
13 |
14 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/doubleencore/mpatterson/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.doubleencore.mpatterson;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.view.View;
7 | import android.widget.ImageView;
8 |
9 | import com.doubleencore.mpatterson.exoplayer.ExoPlayerActivity;
10 |
11 | public class MainActivity extends Activity {
12 | private static final String TAG = MainActivity.class.getSimpleName();
13 |
14 | private ImageView mPlayButton;
15 |
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_main);
20 |
21 | mPlayButton = (ImageView) findViewById(R.id.play_button);
22 | mPlayButton.setOnClickListener(new View.OnClickListener() {
23 | @Override
24 | public void onClick(View v) {
25 | Intent intent = new Intent(MainActivity.this, ExoPlayerActivity.class);
26 | intent.putExtra(ExoPlayerActivity.EXTRA_URL, getString(R.string.video_url));
27 | startActivity(intent);
28 | }
29 | });
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/video_controls.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
16 |
17 |
22 |
23 |
29 |
30 |
39 |
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/doubleencore/mpatterson/controls/ControlsContainer.java:
--------------------------------------------------------------------------------
1 | package com.doubleencore.mpatterson.controls;
2 |
3 | import android.content.Context;
4 | import android.os.Handler;
5 | import android.util.AttributeSet;
6 | import android.view.View;
7 | import android.widget.FrameLayout;
8 |
9 | /**
10 | * Created by michael on 11/27/15.
11 | */
12 | public class ControlsContainer extends FrameLayout {
13 |
14 | private static final int HIDE_DELAY = 4117;
15 |
16 | private VideoControlsView mControls;
17 | private Handler mHandler;
18 |
19 | public ControlsContainer(Context context) {
20 | this(context, null);
21 | }
22 |
23 | public ControlsContainer(Context context, AttributeSet attrs) {
24 | this(context, attrs, 0);
25 | }
26 |
27 | public ControlsContainer(Context context, AttributeSet attrs, int defStyleAttr) {
28 | super(context, attrs, defStyleAttr);
29 | mHandler = new Handler();
30 | setOnClickListener(new OnClickListener() {
31 | @Override
32 | public void onClick(View v) {
33 | if (mControls != null) {
34 | mControls.setVisibility(VISIBLE);
35 | mHandler.removeCallbacks(mHideControls);
36 | mHandler.postDelayed(mHideControls, HIDE_DELAY);
37 | }
38 | }
39 | });
40 | mHandler.postDelayed(mHideControls, HIDE_DELAY);
41 | }
42 |
43 | private Runnable mHideControls = new Runnable() {
44 | @Override
45 | public void run() {
46 | if (mControls.isBuffering()) {
47 | mHandler.postDelayed(mHideControls, 1000);
48 | } else {
49 | mControls.setVisibility(GONE);
50 | }
51 | }
52 | };
53 |
54 | @Override
55 | public void addView(View child) {
56 | super.addView(child);
57 | if (mControls == null && child instanceof VideoControlsView) {
58 | mControls = (VideoControlsView) child;
59 | } else if (mControls != null) {
60 | throw new IllegalStateException("ControlsContainer can only hold one view");
61 | } else {
62 | throw new IllegalStateException("ControlsContainer can only have sub views of type VideoControlsView");
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/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 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
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 Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/com/doubleencore/mpatterson/exoplayer/ExoPlayerActivity.java:
--------------------------------------------------------------------------------
1 | package com.doubleencore.mpatterson.exoplayer;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.media.AudioManager;
6 | import android.os.Bundle;
7 | import android.widget.Toast;
8 |
9 | import com.doubleencore.mpatterson.R;
10 | import com.doubleencore.mpatterson.controls.ControlsContainer;
11 | import com.doubleencore.mpatterson.controls.VideoControlsView;
12 | import com.doubleencore.mpatterson.interfaces.IEndedListener;
13 |
14 | /**
15 | * Created by michael on 9/2/15.
16 | */
17 | public class ExoPlayerActivity extends Activity implements IEndedListener, AudioManager.OnAudioFocusChangeListener {
18 | private static final String TAG = ExoPlayerActivity.class.getSimpleName();
19 |
20 | public static final String EXTRA_URL = "extra_url";
21 |
22 | private VideoPlayerView mPlayerView;
23 | private AudioManager mAudioManager;
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.video_player);
29 | mPlayerView = (VideoPlayerView) findViewById(R.id.player_view);
30 |
31 | VideoControlsView controlsView = new VideoControlsView(this);
32 | controlsView.setControlsListener(mPlayerView);
33 |
34 | ControlsContainer controlsContainer = (ControlsContainer) findViewById(R.id.controls_container);
35 | controlsContainer.addView(controlsView);
36 |
37 | mPlayerView.setPlayerListener(controlsView);
38 | mPlayerView.setEndedListener(this);
39 | mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
40 |
41 | Intent intent = getIntent();
42 | if (intent.hasExtra(EXTRA_URL)) {
43 | String url = intent.getStringExtra(EXTRA_URL);
44 | mPlayerView.setUrl(url);
45 | } else {
46 | showError();
47 | }
48 | }
49 |
50 | @Override
51 | protected void onResume() {
52 | super.onResume();
53 | mPlayerView.preparePlayer();
54 | mAudioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
55 | }
56 |
57 | @Override
58 | protected void onPause() {
59 | super.onPause();
60 | mPlayerView.releasePlayer();
61 | }
62 |
63 | @Override
64 | protected void onDestroy() {
65 | super.onDestroy();
66 | mPlayerView.destroyPlayer();
67 | }
68 |
69 | private void showError() {
70 | Toast.makeText(this, R.string.video_player_error, Toast.LENGTH_SHORT).show();
71 | finish();
72 | }
73 |
74 | @Override
75 | public void onEnded() {
76 | finish();
77 | }
78 |
79 | @Override
80 | public void onAudioFocusChange(int focusChange) {
81 | switch (focusChange) {
82 | case AudioManager.AUDIOFOCUS_GAIN:
83 | // dont do anything
84 | // should happen after onResume when we requestAudioFocus
85 | break;
86 | case AudioManager.AUDIOFOCUS_LOSS:
87 | mPlayerView.onPause();
88 | break;
89 | case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
90 | case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
91 | // just keep playing for short interruptions, ie notification noises
92 | break;
93 | }
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/app/src/main/java/com/doubleencore/mpatterson/exoplayer/VideoPlayerView.java:
--------------------------------------------------------------------------------
1 | package com.doubleencore.mpatterson.exoplayer;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.util.Log;
6 |
7 | import com.doubleencore.mpatterson.interfaces.IControlsListener;
8 | import com.doubleencore.mpatterson.interfaces.IEndedListener;
9 | import com.doubleencore.mpatterson.interfaces.IPlayerListener;
10 | import com.google.android.exoplayer.ExoPlayer;
11 |
12 | /**
13 | * Created by michael on 11/26/15.
14 | * Use this view to communicate with controls and listen to player state
15 | */
16 | public class VideoPlayerView extends AbsVideoPlayer implements IControlsListener {
17 |
18 | private IPlayerListener mPlayerListener;
19 | private IEndedListener mEndedListener;
20 | private boolean mShouldSetDuration;
21 |
22 | public VideoPlayerView(Context context) {
23 | this(context, null, 0);
24 | }
25 |
26 | public VideoPlayerView(Context context, AttributeSet attrs) {
27 | this(context, attrs, 0);
28 | }
29 |
30 | public VideoPlayerView(Context context, AttributeSet attrs, int defStyleAttr) {
31 | super(context, attrs, defStyleAttr);
32 | mShouldSetDuration = true;
33 | }
34 |
35 | public void setPlayerListener(IPlayerListener listener) {
36 | mPlayerListener = listener;
37 | }
38 |
39 | public void setEndedListener(IEndedListener listener) {
40 | mEndedListener = listener;
41 | }
42 |
43 | @Override
44 | public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
45 | Log.v(EXOPLAYER_LISTENER, "onPlayerStateChanged");
46 | switch(playbackState) {
47 | case ExoPlayer.STATE_BUFFERING:
48 | mPlayerListener.onBufferingStart();
49 | break;
50 | case ExoPlayer.STATE_READY:
51 | mPlayerListener.onBufferingComplete();
52 | if (mShouldSetDuration) {
53 | mPlayerListener.onSetDuration(mExoPlayer.getDuration());
54 | mPlayerListener.onUpdateProgress(0);
55 | mHandler.post(mUpdateProgress);
56 | mShouldSetDuration = false;
57 | }
58 | break;
59 | case ExoPlayer.STATE_ENDED:
60 | mEndedListener.onEnded();
61 | break;
62 | }
63 | }
64 |
65 | @Override
66 | public void onPause() {
67 | if (mPlayerController != null) {
68 | mPlayerController.pause();
69 | }
70 | }
71 |
72 | @Override
73 | public void onPlay() {
74 | if (mPlayerController != null) {
75 | mPlayerController.start();
76 | }
77 | }
78 |
79 | @Override
80 | public void onSeekTo(float percentComplete) {
81 | if (mPlayerController != null && mExoPlayer != null) {
82 | mPlayerController.seekTo((int) (mExoPlayer.getDuration()*percentComplete));
83 | }
84 | }
85 |
86 | @Override
87 | public void onControlsHidden() {
88 | mHandler.removeCallbacks(mUpdateProgress);
89 | }
90 |
91 | @Override
92 | public void onControlsShown() {
93 | mHandler.removeCallbacks(mUpdateProgress);
94 | mHandler.post(mUpdateProgress);
95 | }
96 |
97 | private Runnable mUpdateProgress = new Runnable() {
98 | @Override
99 | public void run() {
100 | if (mPlayerListener == null || mPlayerController == null) return;
101 |
102 | mPlayerListener.onUpdateProgress(mPlayerController.getCurrentPosition() / (float) mPlayerController.getDuration());
103 | mHandler.postDelayed(mUpdateProgress, 1000);
104 | }
105 | };
106 | }
107 |
--------------------------------------------------------------------------------
/app/src/main/java/com/doubleencore/mpatterson/exoplayer/AbsVideoPlayerImpl.java:
--------------------------------------------------------------------------------
1 | package com.doubleencore.mpatterson.exoplayer;
2 |
3 | import android.content.Context;
4 | import android.media.MediaCodec;
5 | import android.util.AttributeSet;
6 | import android.util.Log;
7 | import android.view.Surface;
8 | import android.view.SurfaceHolder;
9 | import android.widget.FrameLayout;
10 |
11 | import com.google.android.exoplayer.ExoPlaybackException;
12 | import com.google.android.exoplayer.ExoPlayer;
13 | import com.google.android.exoplayer.MediaCodecAudioTrackRenderer;
14 | import com.google.android.exoplayer.MediaCodecTrackRenderer;
15 | import com.google.android.exoplayer.MediaCodecVideoTrackRenderer;
16 | import com.google.android.exoplayer.audio.AudioTrack;
17 | import com.google.android.exoplayer.chunk.Format;
18 | import com.google.android.exoplayer.hls.HlsSampleSource;
19 |
20 | import java.io.IOException;
21 |
22 | /**
23 | * Created by michael on 11/26/15.
24 | */
25 | public abstract class AbsVideoPlayerImpl extends FrameLayout implements HlsSampleSource.EventListener,
26 | MediaCodecVideoTrackRenderer.EventListener, MediaCodecAudioTrackRenderer.EventListener,
27 | ExoPlayer.Listener, SurfaceHolder.Callback {
28 |
29 | private static final String SAMPLE_SOURCE_LISTENER = "SampleSource.Listener";
30 | private static final String TRACK_RENDERER_LISTENER = "TrackRenderer.Listener";
31 | private static final String VIDEO_TRACK_LISTENER = "VideoTrack.Listener";
32 | private static final String AUDIO_TRACK_LISTENER = "AudioTrack.Listener";
33 | protected static final String EXOPLAYER_LISTENER = "ExoPlayer.Listener";
34 | private static final String SURFACE_HOLDER_CALLBACK = "SurfaceHolder.Callback";
35 |
36 |
37 | public AbsVideoPlayerImpl(Context context, AttributeSet attrs, int defStyleAttr) {
38 | super(context, attrs, defStyleAttr);
39 | }
40 |
41 | @Override
42 | public void onLoadStarted(int sourceId, long length, int type, int trigger, Format format, long mediaStartTimeMs, long mediaEndTimeMs) {
43 | Log.v(SAMPLE_SOURCE_LISTENER, "onLoadStarted");
44 | }
45 |
46 | @Override
47 | public void onLoadCompleted(int sourceId, long bytesLoaded, int type, int trigger, Format format, long mediaStartTimeMs, long mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs) {
48 | Log.v(SAMPLE_SOURCE_LISTENER, "onLoadCompleted");
49 | }
50 |
51 | @Override
52 | public void onLoadCanceled(int sourceId, long bytesLoaded) {
53 | Log.v(SAMPLE_SOURCE_LISTENER, "onLoadCanceled");
54 | }
55 |
56 | @Override
57 | public void onLoadError(int sourceId, IOException e) {
58 | Log.e(SAMPLE_SOURCE_LISTENER, "onLoadError", e);
59 | }
60 |
61 | @Override
62 | public void onUpstreamDiscarded(int sourceId, long mediaStartTimeMs, long mediaEndTimeMs) {
63 | Log.v(SAMPLE_SOURCE_LISTENER, "onUpstreamDiscarded");
64 | }
65 |
66 | @Override
67 | public void onDownstreamFormatChanged(int sourceId, Format format, int trigger, long mediaTimeMs) {
68 | Log.v(SAMPLE_SOURCE_LISTENER, "onDownstreamFormatChanged");
69 | }
70 |
71 | @Override
72 | public void onDecoderInitializationError(MediaCodecTrackRenderer.DecoderInitializationException e) {
73 | Log.e(TRACK_RENDERER_LISTENER, "onDecoderInitializationError", e);
74 | }
75 |
76 | @Override
77 | public void onCryptoError(MediaCodec.CryptoException e) {
78 | Log.e(TRACK_RENDERER_LISTENER, "onCryptoError", e);
79 | }
80 |
81 | @Override
82 | public void onDecoderInitialized(String decoderName, long elapsedRealtimeMs, long initializationDurationMs) {
83 | Log.v(TRACK_RENDERER_LISTENER, "onDecoderInitialized");
84 | }
85 |
86 | @Override
87 | public void onDroppedFrames(int count, long elapsed) {
88 | Log.v(VIDEO_TRACK_LISTENER, "onDroppedFrames");
89 | }
90 |
91 | @Override
92 | public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) {
93 | Log.v(VIDEO_TRACK_LISTENER, "onVideoSizeChanged");
94 | }
95 |
96 | @Override
97 | public void onDrawnToSurface(Surface surface) {
98 | Log.v(VIDEO_TRACK_LISTENER, "onDrawnToSurface");
99 | }
100 |
101 | @Override
102 | public void onAudioTrackInitializationError(AudioTrack.InitializationException e) {
103 | Log.v(AUDIO_TRACK_LISTENER, "onAudioTrackInitializationError");
104 | }
105 |
106 | @Override
107 | public void onAudioTrackWriteError(AudioTrack.WriteException e) {
108 | Log.e(AUDIO_TRACK_LISTENER, "onAudioTrackWriteError", e);
109 | }
110 |
111 | @Override
112 | public void onAudioTrackUnderrun(int bufferSize, long bufferSizeMs, long elapsedSinceLastFeedMs) {
113 | Log.e(AUDIO_TRACK_LISTENER, "onAudioTrackUnderrun");
114 | }
115 |
116 | @Override
117 | public void onPlayWhenReadyCommitted() {
118 | Log.v(EXOPLAYER_LISTENER, "onPlayWhenReadyCommitted");
119 | }
120 |
121 | @Override
122 | public void onPlayerError(ExoPlaybackException e) {
123 | Log.e(EXOPLAYER_LISTENER, "onPlayerError", e);
124 | }
125 |
126 | @Override
127 | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
128 | Log.v(SURFACE_HOLDER_CALLBACK, "surfaceChanged");
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/app/src/main/java/com/doubleencore/mpatterson/exoplayer/HlsRendererBuilder.java:
--------------------------------------------------------------------------------
1 | package com.doubleencore.mpatterson.exoplayer;
2 |
3 | import android.content.Context;
4 | import android.media.MediaCodec;
5 | import android.os.Handler;
6 |
7 | import com.doubleencore.mpatterson.R;
8 | import com.google.android.exoplayer.DefaultLoadControl;
9 | import com.google.android.exoplayer.LoadControl;
10 | import com.google.android.exoplayer.MediaCodecAudioTrackRenderer;
11 | import com.google.android.exoplayer.MediaCodecSelector;
12 | import com.google.android.exoplayer.MediaCodecVideoTrackRenderer;
13 | import com.google.android.exoplayer.TrackRenderer;
14 | import com.google.android.exoplayer.audio.AudioCapabilities;
15 | import com.google.android.exoplayer.chunk.VideoFormatSelectorUtil;
16 | import com.google.android.exoplayer.extractor.ts.PtsTimestampAdjuster;
17 | import com.google.android.exoplayer.hls.DefaultHlsTrackSelector;
18 | import com.google.android.exoplayer.hls.HlsChunkSource;
19 | import com.google.android.exoplayer.hls.HlsMasterPlaylist;
20 | import com.google.android.exoplayer.hls.HlsPlaylist;
21 | import com.google.android.exoplayer.hls.HlsPlaylistParser;
22 | import com.google.android.exoplayer.hls.HlsSampleSource;
23 | import com.google.android.exoplayer.hls.HlsTrackSelector;
24 | import com.google.android.exoplayer.hls.PtsTimestampAdjusterProvider;
25 | import com.google.android.exoplayer.upstream.DataSource;
26 | import com.google.android.exoplayer.upstream.DefaultAllocator;
27 | import com.google.android.exoplayer.upstream.DefaultBandwidthMeter;
28 | import com.google.android.exoplayer.upstream.DefaultUriDataSource;
29 | import com.google.android.exoplayer.util.ManifestFetcher;
30 | import com.google.android.exoplayer.util.Util;
31 |
32 | import java.io.IOException;
33 |
34 | /**
35 | * Created by michael on 11/26/15.
36 | */
37 | public class HlsRendererBuilder implements ManifestFetcher.ManifestCallback {
38 |
39 | public interface Listener {
40 | void onSuccess(TrackRenderer[] renderers);
41 | void onFailure(Exception e);
42 | }
43 |
44 | private Context mContext;
45 | private String mUserAgent;
46 | private String mUrl;
47 | private Handler mHandler;
48 | private AbsVideoPlayer mPlayer;
49 | private boolean mCanceled;
50 |
51 | public HlsRendererBuilder() { }
52 |
53 | public void build(Context context, AbsVideoPlayer player, String url) {
54 | mContext = context;
55 | mUserAgent = Util.getUserAgent(mContext, mContext.getString(R.string.app_name));
56 | mHandler = player.getMainHandler();
57 | mPlayer = player;
58 | mUrl = url;
59 |
60 | HlsPlaylistParser parser = new HlsPlaylistParser();
61 | ManifestFetcher playlistFetcher = new ManifestFetcher<>(mUrl,
62 | new DefaultUriDataSource(mContext, mUserAgent), parser);
63 | mCanceled = false;
64 | playlistFetcher.singleLoad(mHandler.getLooper(), this);
65 | }
66 |
67 | public void cancel() {
68 | mCanceled = true;
69 | }
70 |
71 | @Override
72 | public void onSingleManifest(HlsPlaylist manifest) {
73 | if (mCanceled) return;
74 |
75 | if (manifest == null || ! (manifest instanceof HlsMasterPlaylist)) {
76 | mPlayer.onFailure(new IllegalStateException("Failed to retrieve a valid hlsPlaylist"));
77 | return;
78 | }
79 |
80 | HlsMasterPlaylist masterPlaylist = (HlsMasterPlaylist) manifest;
81 | int[] variants;
82 | try {
83 | variants = VideoFormatSelectorUtil.selectVideoFormatsForDefaultDisplay(mContext, masterPlaylist.variants, null, false);
84 | } catch (Exception e) {
85 | mPlayer.onFailure(e);
86 | return;
87 | }
88 | if (variants.length == 0) {
89 | mPlayer.onFailure(new IllegalStateException("No variants selected from manifest"));
90 | return;
91 | }
92 |
93 | LoadControl loadControl = new DefaultLoadControl(new DefaultAllocator(AbsVideoPlayer.BUFFER_SEGMENT_SIZE));
94 | DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
95 | DataSource dataSource = new DefaultUriDataSource(mContext, bandwidthMeter, mUserAgent);
96 |
97 | HlsChunkSource chunkSource = new HlsChunkSource(true, dataSource, mUrl, manifest,
98 | DefaultHlsTrackSelector.newDefaultInstance(mContext), bandwidthMeter,
99 | new PtsTimestampAdjusterProvider(), HlsChunkSource.ADAPTIVE_MODE_SPLICE);
100 | HlsSampleSource sampleSource = new HlsSampleSource(chunkSource, loadControl,
101 | AbsVideoPlayer.BUFFER_SEGMENT_SIZE * AbsVideoPlayer.BUFFER_SEGMENT_COUNT, mHandler, mPlayer, 0);
102 | MediaCodecVideoTrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(mContext, sampleSource,
103 | MediaCodecSelector.DEFAULT, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING,
104 | AbsVideoPlayer.ALLOWED_JOIN_TIME_MS, mHandler, mPlayer, AbsVideoPlayer.MAX_DROPPED_FRAMES);
105 | MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource,
106 | MediaCodecSelector.DEFAULT, null, true, mHandler, mPlayer);
107 |
108 | TrackRenderer[] renderers = new TrackRenderer[AbsVideoPlayer.RENDERER_COUNT];
109 | renderers[AbsVideoPlayer.VIDEO_RENDERER] = videoRenderer;
110 | renderers[AbsVideoPlayer.AUDIO_RENDERER] = audioRenderer;
111 | mPlayer.onSuccess(renderers);
112 | }
113 |
114 | @Override
115 | public void onSingleManifestError(IOException e) {
116 | if (mCanceled) return;
117 |
118 | mPlayer.onFailure(e);
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
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 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/app/src/main/java/com/doubleencore/mpatterson/controls/VideoControlsView.java:
--------------------------------------------------------------------------------
1 | package com.doubleencore.mpatterson.controls;
2 |
3 | import android.content.Context;
4 | import android.text.TextUtils;
5 | import android.util.AttributeSet;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.widget.ImageView;
9 | import android.widget.ProgressBar;
10 | import android.widget.RelativeLayout;
11 | import android.widget.SeekBar;
12 | import android.widget.TextView;
13 |
14 | import com.doubleencore.mpatterson.R;
15 | import com.doubleencore.mpatterson.interfaces.IControlsListener;
16 | import com.doubleencore.mpatterson.interfaces.IPlayerListener;
17 |
18 | /**
19 | * Created by michael on 11/27/15.
20 | */
21 | public class VideoControlsView extends RelativeLayout implements IPlayerListener {
22 |
23 | private static final String TIMER_FORMAT = "%s / %s";
24 | private static final int ONE_MINUTE = 60;
25 | private static final int ONE_HOUR = ONE_MINUTE*60;
26 |
27 | private IControlsListener mListener;
28 |
29 | private ImageView mPlayButton;
30 | private ProgressBar mBuffering;
31 | private SeekBar mSeekBar;
32 | private TextView mTimer;
33 |
34 | private int mDurationSec;
35 | private String mTimeFormat;
36 |
37 | public VideoControlsView(Context context) {
38 | this(context, null);
39 | }
40 |
41 | public VideoControlsView(Context context, AttributeSet attrs) {
42 | this(context, attrs, 0);
43 | }
44 |
45 | public VideoControlsView(Context context, AttributeSet attrs, int defStyleAttr) {
46 | super(context, attrs, defStyleAttr);
47 | View v = LayoutInflater.from(context).inflate(R.layout.video_controls, this, true);
48 | mPlayButton = (ImageView) v.findViewById(R.id.play_button);
49 | mBuffering = (ProgressBar) v.findViewById(R.id.loading_indicator);
50 | mSeekBar = (SeekBar) v.findViewById(R.id.seekbar);
51 | mTimer = (TextView) v.findViewById(R.id.progress_timer);
52 | mDurationSec = -1;
53 | setViewListeners();
54 | showBuffering();
55 | }
56 |
57 | private void setViewListeners() {
58 | mPlayButton.setOnClickListener(new OnClickListener() {
59 | @Override
60 | public void onClick(View v) {
61 | if (mListener == null) return;
62 |
63 | mPlayButton.setActivated(!mPlayButton.isActivated());
64 | if (mPlayButton.isActivated()) {
65 | mListener.onPause();
66 | } else {
67 | mListener.onPlay();
68 | }
69 | }
70 | });
71 | mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
72 | @Override
73 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
74 | }
75 |
76 | @Override
77 | public void onStartTrackingTouch(SeekBar seekBar) {
78 | }
79 |
80 | @Override
81 | public void onStopTrackingTouch(SeekBar seekBar) {
82 | if (mListener != null) {
83 | mListener.onSeekTo(seekBar.getProgress() / (float) seekBar.getMax());
84 | }
85 | }
86 | });
87 | }
88 |
89 | private void showBuffering() {
90 | mPlayButton.setVisibility(GONE);
91 | mBuffering.setVisibility(VISIBLE);
92 | }
93 |
94 | private void hideBuffering() {
95 | mBuffering.setVisibility(GONE);
96 | mPlayButton.setVisibility(VISIBLE);
97 | }
98 |
99 | public boolean isBuffering() {
100 | return mBuffering.getVisibility() == VISIBLE;
101 | }
102 |
103 | @Override
104 | public void setVisibility(int visibility) {
105 | super.setVisibility(visibility);
106 | if (mListener == null) return;
107 |
108 | if (visibility == GONE || visibility == INVISIBLE) {
109 | mListener.onControlsHidden();
110 | } else {
111 | mListener.onControlsShown();
112 | }
113 | }
114 |
115 | public void setControlsListener(IControlsListener listener) {
116 | mListener = listener;
117 | }
118 |
119 | @Override
120 | public void onBufferingStart() {
121 | showBuffering();
122 | }
123 |
124 | @Override
125 | public void onBufferingComplete() {
126 | hideBuffering();
127 | }
128 |
129 | @Override
130 | public void onSetDuration(long durationMs) {
131 | mDurationSec = (int) (durationMs / 1000);
132 | if (mDurationSec >= 10 * ONE_HOUR) {
133 | mTimeFormat = "%02d:%02d:%02d";
134 | } else if (mDurationSec >= ONE_HOUR) {
135 | mTimeFormat = "%1d:%02d:%02d";
136 | } else if (mDurationSec >= 10 * ONE_MINUTE) {
137 | mTimeFormat = "%02d:%02d";
138 | } else {
139 | mTimeFormat = "%1d:%02d";
140 | }
141 | }
142 |
143 | @Override
144 | public void onUpdateProgress(float percentComplete) {
145 | mSeekBar.setProgress((int) (mSeekBar.getMax()*percentComplete));
146 | if (mDurationSec > 0) {
147 | mTimer.setText(String.format(TIMER_FORMAT, formatTime((int) (mDurationSec * percentComplete)),
148 | formatTime(mDurationSec)));
149 | }
150 | }
151 |
152 | private String formatTime(int timeSec) {
153 | if (TextUtils.isEmpty(mTimeFormat)) return "00:00";
154 |
155 | int hours = timeSec / ONE_HOUR;
156 | int remainder = timeSec % ONE_HOUR;
157 | int minutes = remainder / ONE_MINUTE;
158 | int seconds = remainder % ONE_MINUTE;
159 | if (mTimeFormat.length() > 9) {
160 | return String.format(mTimeFormat, hours, minutes, seconds);
161 | } else {
162 | return String.format(mTimeFormat, minutes, seconds);
163 | }
164 | }
165 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/doubleencore/mpatterson/exoplayer/AbsVideoPlayer.java:
--------------------------------------------------------------------------------
1 | package com.doubleencore.mpatterson.exoplayer;
2 |
3 | import android.content.Context;
4 | import android.os.Handler;
5 | import android.util.AttributeSet;
6 | import android.util.Log;
7 | import android.view.Gravity;
8 | import android.view.SurfaceHolder;
9 | import android.view.SurfaceView;
10 | import android.widget.FrameLayout;
11 |
12 | import com.google.android.exoplayer.AspectRatioFrameLayout;
13 | import com.google.android.exoplayer.ExoPlayer;
14 | import com.google.android.exoplayer.MediaCodecVideoTrackRenderer;
15 | import com.google.android.exoplayer.TrackRenderer;
16 | import com.google.android.exoplayer.audio.AudioCapabilities;
17 | import com.google.android.exoplayer.audio.AudioCapabilitiesReceiver;
18 | import com.google.android.exoplayer.util.PlayerControl;
19 |
20 | /**
21 | * Created by michael on 11/26/15.
22 | * This class handles underlying business to set up the exoplayer
23 | */
24 | public abstract class AbsVideoPlayer extends AbsVideoPlayerImpl implements AudioCapabilitiesReceiver.Listener,
25 | HlsRendererBuilder.Listener {
26 |
27 | private static final String TAG = AbsVideoPlayer.class.getSimpleName();
28 |
29 | // custom vars for the exoplayer
30 | // can be adjusted for different playback needs
31 | private static final int MIN_BUFFER_MS = 1500;
32 | private static final int MIN_REBUFFER_MS = 4000;
33 | public static final int BUFFER_SEGMENT_SIZE = 64*1024;
34 | public static final int BUFFER_SEGMENT_COUNT = 150;
35 | public static final int ALLOWED_JOIN_TIME_MS = 5000;
36 | public static final int MAX_DROPPED_FRAMES = 50;
37 | // track renderer positions. could also include captions or metadata tracks
38 | public static final int RENDERER_COUNT = 2;
39 | public static final int VIDEO_RENDERER = 0;
40 | public static final int AUDIO_RENDERER = 1;
41 |
42 | private String mUrl;
43 | private SurfaceHolder mSurfaceHolder;
44 | private HlsRendererBuilder mBuilder;
45 | private AudioCapabilitiesReceiver mAudioCapabilitiesReceiver;
46 | private MediaCodecVideoTrackRenderer mVideoRenderer;
47 | private long mPreviousPosition;
48 | protected ExoPlayer mExoPlayer;
49 | protected PlayerControl mPlayerController;
50 | protected Handler mHandler;
51 |
52 | public AbsVideoPlayer(Context context) {
53 | this(context, null);
54 | }
55 |
56 | public AbsVideoPlayer(Context context, AttributeSet attrs) {
57 | this(context, attrs, 0);
58 | }
59 |
60 | public AbsVideoPlayer(Context context, AttributeSet attrs, int defStyleAttr) {
61 | super(context, attrs, defStyleAttr);
62 | init();
63 | }
64 |
65 | private void init() {
66 | AspectRatioFrameLayout frame = new AspectRatioFrameLayout(this.getContext());
67 | this.addView(frame);
68 |
69 | SurfaceView surfaceView = new SurfaceView(this.getContext());
70 | mSurfaceHolder = surfaceView.getHolder();
71 | frame.addView(surfaceView);
72 | mSurfaceHolder.addCallback(this);
73 |
74 | mAudioCapabilitiesReceiver = new AudioCapabilitiesReceiver(getContext(), this);
75 | mAudioCapabilitiesReceiver.register();
76 | mHandler= new Handler();
77 | mBuilder = new HlsRendererBuilder();
78 | }
79 |
80 | public void destroyPlayer() {
81 | mAudioCapabilitiesReceiver.unregister();
82 | releasePlayer();
83 | }
84 |
85 | public void setUrl(String url) {
86 | mUrl = url;
87 | }
88 |
89 | public void releasePlayer() {
90 | if (mExoPlayer != null) {
91 | mPreviousPosition = mExoPlayer.getCurrentPosition();
92 | mExoPlayer.release();
93 | mExoPlayer = null;
94 | mPlayerController = null;
95 | mBuilder.cancel();
96 | }
97 | }
98 |
99 | public void preparePlayer() {
100 | if (mExoPlayer == null) {
101 | mExoPlayer = ExoPlayer.Factory.newInstance(RENDERER_COUNT, MIN_BUFFER_MS, MIN_REBUFFER_MS);
102 | mPlayerController = new PlayerControl(mExoPlayer);
103 | mExoPlayer.setPlayWhenReady(true);
104 | mExoPlayer.addListener(this);
105 | mBuilder.build(getContext(), this, mUrl);
106 | }
107 | }
108 |
109 | public Handler getMainHandler() {
110 | return mHandler;
111 | }
112 |
113 | @Override
114 | public void onAudioCapabilitiesChanged(AudioCapabilities audioCapabilities) {
115 | // called when phone has hdmi cord plugged in or unplugged
116 | // wont worry about it for this demo cause I dont have a good way to test
117 | // should probably release then re-prepare the player
118 | }
119 |
120 | @Override
121 | public void onSuccess(TrackRenderer[] renderers) {
122 | mVideoRenderer = (MediaCodecVideoTrackRenderer) renderers[VIDEO_RENDERER];
123 | mExoPlayer.sendMessage(mVideoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, mSurfaceHolder.getSurface());
124 | mExoPlayer.seekTo(mPreviousPosition);
125 | mExoPlayer.prepare(renderers);
126 | }
127 |
128 | @Override
129 | public void onFailure(Exception e) {
130 | Log.e(TAG, "HlsRendererBuilder failed", e);
131 | }
132 |
133 | @Override
134 | public void surfaceCreated(SurfaceHolder holder) {
135 | if (mVideoRenderer != null && mExoPlayer != null) {
136 | mExoPlayer.sendMessage(mVideoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, mSurfaceHolder.getSurface());
137 | }
138 | }
139 |
140 | @Override
141 | public void surfaceDestroyed(SurfaceHolder holder) {
142 | if (mVideoRenderer != null && mExoPlayer != null) {
143 | mExoPlayer.blockingSendMessage(mVideoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, mSurfaceHolder.getSurface());
144 | }
145 | }
146 | }
147 |
--------------------------------------------------------------------------------