├── .idea
├── .name
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── runConfigurations.xml
└── gradle.xml
├── demo
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── strings.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── styles.xml
│ │ │ ├── layout
│ │ │ │ ├── fragment_basic.xml
│ │ │ │ ├── player_layout.xml
│ │ │ │ ├── fragment_chooser.xml
│ │ │ │ ├── fragment_exoplayerview.xml
│ │ │ │ └── activity_main.xml
│ │ │ ├── values-v21
│ │ │ │ └── styles.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── menu
│ │ │ │ └── menu_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── io
│ │ │ └── gresse
│ │ │ └── hugo
│ │ │ └── simpleexoplayerdemo
│ │ │ ├── ExoPlayerViewFragment.java
│ │ │ ├── ChooserFragment.java
│ │ │ ├── BasicFragment.java
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── io
│ │ │ └── gresse
│ │ │ └── hugo
│ │ │ └── simpleexoplayer
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── io
│ │ └── gresse
│ │ └── hugo
│ │ └── simpleexoplayerdemo
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── library
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── ids.xml
│ │ │ │ └── attr_exoplayerview.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── io
│ │ │ └── gresse
│ │ │ └── hugo
│ │ │ └── simpleexoplayer
│ │ │ ├── view
│ │ │ ├── VideoSurfaceInterface.java
│ │ │ ├── ExoplayerView.java
│ │ │ └── AspectRatioTextureView.java
│ │ │ ├── player
│ │ │ ├── SimpleExoPlayerListener.java
│ │ │ ├── base
│ │ │ │ ├── ExtractorRendererBuilder.java
│ │ │ │ ├── EventLogger.java
│ │ │ │ └── DemoPlayer.java
│ │ │ ├── VideoPlayer.java
│ │ │ └── SimpleExoPlayer.java
│ │ │ ├── MediaFile.java
│ │ │ └── util
│ │ │ └── Utils.java
│ ├── test
│ │ └── java
│ │ │ └── io
│ │ │ └── gresse
│ │ │ └── hugo
│ │ │ └── simpleexoplayer
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── io
│ │ └── gresse
│ │ └── hugo
│ │ └── simpleexoplayer
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── makefile
├── gradle.properties
├── README.md
├── gradlew.bat
├── gradlew
└── LICENSE
/.idea/.name:
--------------------------------------------------------------------------------
1 | SimpleExoplayer
--------------------------------------------------------------------------------
/demo/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':demo', ':library'
2 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
28 | * This tolerance allows the view to occupy the whole of the screen when the requested aspect
29 | * ratio is very close, but not exactly equal to, the aspect ratio of the screen. This may reduce
30 | * the number of view layers that need to be composited by the underlying system, which can help
31 | * to reduce power consumption.
32 | */
33 | private static final float MAX_ASPECT_RATIO_DEFORMATION_FRACTION = 0.01f;
34 |
35 | private float mVideoAspectRatio;
36 |
37 | /**
38 | * External listener to we can save is view has been created or not
39 | */
40 | @Nullable
41 | private SurfaceTextureListener mExternalListener;
42 |
43 | private int mLastState;
44 | private SurfaceTexture mLastSurfaceTexture;
45 | public boolean mSurfaceAvailable;
46 |
47 | public AspectRatioTextureView(Context context) {
48 | super(context);
49 | setInternalListener();
50 | }
51 |
52 | public AspectRatioTextureView(Context context, AttributeSet attrs) {
53 | super(context, attrs);
54 | setInternalListener();
55 | }
56 |
57 | public AspectRatioTextureView(Context context, AttributeSet attrs, int defStyleAttr) {
58 | super(context, attrs, defStyleAttr);
59 | setInternalListener();
60 | }
61 |
62 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
63 | public AspectRatioTextureView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
64 | super(context, attrs, defStyleAttr, defStyleRes);
65 | setInternalListener();
66 | }
67 |
68 | private void setInternalListener(){
69 | super.setSurfaceTextureListener(this);
70 | }
71 |
72 | /**
73 | * Set the aspect ratio that this {@link AspectRatioTextureView} should satisfy.
74 | *
75 | * @param widthHeightRatio The width to height ratio.
76 | */
77 | @Override
78 | public void setVideoWidthHeightRatio(float widthHeightRatio) {
79 | if (mVideoAspectRatio != widthHeightRatio) {
80 | mVideoAspectRatio = widthHeightRatio;
81 | requestLayout();
82 | }
83 | }
84 |
85 | @Override
86 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
87 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
88 | if (mVideoAspectRatio == 0) {
89 | // Aspect ratio not set.
90 | return;
91 | }
92 |
93 | int width = getMeasuredWidth();
94 | int height = getMeasuredHeight();
95 | float viewAspectRatio = (float) width / height;
96 | float aspectDeformation = mVideoAspectRatio / viewAspectRatio - 1;
97 | if (Math.abs(aspectDeformation) <= MAX_ASPECT_RATIO_DEFORMATION_FRACTION) {
98 | // We're within the allowed tolerance.
99 | return;
100 | }
101 |
102 | if (aspectDeformation > 0) {
103 | height = (int) (width / mVideoAspectRatio);
104 | } else {
105 | width = (int) (height * mVideoAspectRatio);
106 | }
107 | super.onMeasure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
108 | MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
109 | }
110 |
111 | @Override
112 | public void setSurfaceTexture(SurfaceTexture surfaceTexture){
113 | super.setSurfaceTexture(surfaceTexture);
114 | mSurfaceAvailable = surfaceTexture != null;
115 | }
116 |
117 | /**
118 | * Returns the {@link android.view.TextureView.SurfaceTextureListener} currently associated with this
119 | * texture view.
120 | *
121 | * @see #setSurfaceTextureListener(android.view.TextureView.SurfaceTextureListener)
122 | * @see android.view.TextureView.SurfaceTextureListener
123 | */
124 | @Override
125 | public SurfaceTextureListener getSurfaceTextureListener() {
126 | return mExternalListener;
127 | }
128 |
129 | /**
130 | * Sets the {@link android.view.TextureView.SurfaceTextureListener} used to listen to surface
131 | * texture events.
132 | *
133 | * @see #getSurfaceTextureListener()
134 | * @see android.view.TextureView.SurfaceTextureListener
135 | */
136 | @Override
137 | public void setSurfaceTextureListener(SurfaceTextureListener listener) {
138 | if(mExternalListener != null){
139 | // No listener set before, call last TextureView.SurfaceTextureListener callbacks directly on it
140 |
141 | switch (mLastState){
142 | case LASTSTATE_AVAILABLE:
143 | listener.onSurfaceTextureAvailable(mLastSurfaceTexture, 0, 0);
144 | break;
145 | case LASTSTATE_SIZECHANGED:
146 | listener.onSurfaceTextureSizeChanged(mLastSurfaceTexture, 0, 0);
147 | break;
148 | case LASTSTATE_DESTROYED:
149 | listener.onSurfaceTextureDestroyed(mLastSurfaceTexture);
150 | break;
151 | case LASTSTATE_UPDATED:
152 | listener.onSurfaceTextureUpdated(mLastSurfaceTexture);
153 | break;
154 | }
155 | }
156 |
157 | mExternalListener = listener;
158 |
159 | }
160 |
161 |
162 | /*----------------------------------------
163 | * TextureView.SurfaceTextureListener
164 | */
165 |
166 | @Override
167 | public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
168 | mLastState = LASTSTATE_AVAILABLE;
169 | mSurfaceAvailable = true;
170 | mLastSurfaceTexture = surface;
171 | if (mExternalListener != null) {
172 | mExternalListener.onSurfaceTextureAvailable(surface, width, height);
173 | }
174 | }
175 |
176 | @Override
177 | public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
178 | mLastState = LASTSTATE_SIZECHANGED;
179 | mLastSurfaceTexture = surface;
180 | if (mExternalListener != null) {
181 | mExternalListener.onSurfaceTextureSizeChanged(surface, width, height);
182 | }
183 | }
184 |
185 | @Override
186 | public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
187 | mLastState = LASTSTATE_DESTROYED;
188 | mLastSurfaceTexture = surface;
189 | mSurfaceAvailable = false;
190 | if (mExternalListener != null) {
191 | return mExternalListener.onSurfaceTextureDestroyed(surface);
192 | }
193 | return false;
194 | }
195 |
196 | @Override
197 | public void onSurfaceTextureUpdated(SurfaceTexture surface) {
198 | mLastState = LASTSTATE_UPDATED;
199 | mLastSurfaceTexture = surface;
200 | if (mExternalListener != null) {
201 | mExternalListener.onSurfaceTextureUpdated(surface);
202 | }
203 | }
204 | }
205 |
--------------------------------------------------------------------------------
/library/src/main/java/io/gresse/hugo/simpleexoplayer/player/base/EventLogger.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.gresse.hugo.simpleexoplayer.player.base;
17 |
18 | import android.media.MediaCodec.CryptoException;
19 | import android.os.SystemClock;
20 | import android.util.Log;
21 |
22 | import com.google.android.exoplayer.ExoPlayer;
23 | import com.google.android.exoplayer.MediaCodecTrackRenderer;
24 | import com.google.android.exoplayer.TimeRange;
25 | import com.google.android.exoplayer.audio.AudioTrack;
26 | import com.google.android.exoplayer.chunk.Format;
27 | import com.google.android.exoplayer.util.VerboseLogUtil;
28 |
29 | import java.io.IOException;
30 | import java.text.NumberFormat;
31 | import java.util.Locale;
32 |
33 | /**
34 | * Logs player events using {@link android.util.Log}.
35 | */
36 | public class EventLogger implements DemoPlayer.Listener, DemoPlayer.InfoListener,
37 | DemoPlayer.InternalErrorListener {
38 |
39 | private static final String TAG = "EventLogger";
40 | private static final NumberFormat TIME_FORMAT;
41 | static {
42 | TIME_FORMAT = NumberFormat.getInstance(Locale.US);
43 | TIME_FORMAT.setMinimumFractionDigits(2);
44 | TIME_FORMAT.setMaximumFractionDigits(2);
45 | }
46 |
47 | private long sessionStartTimeMs;
48 | private long[] loadStartTimeMs;
49 | private long[] availableRangeValuesUs;
50 |
51 | public EventLogger() {
52 | loadStartTimeMs = new long[DemoPlayer.RENDERER_COUNT];
53 | }
54 |
55 | public void startSession() {
56 | sessionStartTimeMs = SystemClock.elapsedRealtime();
57 | Log.d(TAG, "start [0]");
58 | }
59 |
60 | public void endSession() {
61 | Log.d(TAG, "end [" + getSessionTimeString() + "]");
62 | }
63 |
64 | // DemoPlayer.Listener
65 |
66 | @Override
67 | public void onStateChanged(boolean playWhenReady, int state) {
68 | Log.d(TAG, "state [" + getSessionTimeString() + ", " + playWhenReady + ", "
69 | + getStateString(state) + "]");
70 | }
71 |
72 | @Override
73 | public void onError(Exception e) {
74 | Log.e(TAG, "playerFailed [" + getSessionTimeString() + "]", e);
75 | }
76 |
77 | @Override
78 | public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees,
79 | float pixelWidthHeightRatio) {
80 | Log.d(TAG, "videoSizeChanged [" + width + ", " + height + ", " + unappliedRotationDegrees
81 | + ", " + pixelWidthHeightRatio + "]");
82 | }
83 |
84 | // DemoPlayer.InfoListener
85 |
86 | @Override
87 | public void onBandwidthSample(int elapsedMs, long bytes, long bitrateEstimate) {
88 | Log.d(TAG, "bandwidth [" + getSessionTimeString() + ", " + bytes + ", "
89 | + getTimeString(elapsedMs) + ", " + bitrateEstimate + "]");
90 | }
91 |
92 | @Override
93 | public void onDroppedFrames(int count, long elapsed) {
94 | Log.d(TAG, "droppedFrames [" + getSessionTimeString() + ", " + count + "]");
95 | }
96 |
97 | @Override
98 | public void onLoadStarted(int sourceId, long length, int type, int trigger, Format format,
99 | long mediaStartTimeMs, long mediaEndTimeMs) {
100 | loadStartTimeMs[sourceId] = SystemClock.elapsedRealtime();
101 | if (VerboseLogUtil.isTagEnabled(TAG)) {
102 | Log.v(TAG, "loadStart [" + getSessionTimeString() + ", " + sourceId + ", " + type
103 | + ", " + mediaStartTimeMs + ", " + mediaEndTimeMs + "]");
104 | }
105 | }
106 |
107 | @Override
108 | public void onLoadCompleted(int sourceId, long bytesLoaded, int type, int trigger, Format format,
109 | long mediaStartTimeMs, long mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs) {
110 | if (VerboseLogUtil.isTagEnabled(TAG)) {
111 | long downloadTime = SystemClock.elapsedRealtime() - loadStartTimeMs[sourceId];
112 | Log.v(TAG, "loadEnd [" + getSessionTimeString() + ", " + sourceId + ", " + downloadTime
113 | + "]");
114 | }
115 | }
116 |
117 | @Override
118 | public void onVideoFormatEnabled(Format format, int trigger, long mediaTimeMs) {
119 | Log.d(TAG, "videoFormat [" + getSessionTimeString() + ", " + format.id + ", "
120 | + Integer.toString(trigger) + "]");
121 | }
122 |
123 | @Override
124 | public void onAudioFormatEnabled(Format format, int trigger, long mediaTimeMs) {
125 | Log.d(TAG, "audioFormat [" + getSessionTimeString() + ", " + format.id + ", "
126 | + Integer.toString(trigger) + "]");
127 | }
128 |
129 | // DemoPlayer.InternalErrorListener
130 |
131 | @Override
132 | public void onLoadError(int sourceId, IOException e) {
133 | printInternalError("loadError", e);
134 | }
135 |
136 | @Override
137 | public void onRendererInitializationError(Exception e) {
138 | printInternalError("rendererInitError", e);
139 | }
140 |
141 | @Override
142 | public void onDrmSessionManagerError(Exception e) {
143 | printInternalError("drmSessionManagerError", e);
144 | }
145 |
146 | @Override
147 | public void onDecoderInitializationError(MediaCodecTrackRenderer.DecoderInitializationException e) {
148 | printInternalError("decoderInitializationError", e);
149 | }
150 |
151 | @Override
152 | public void onAudioTrackInitializationError(AudioTrack.InitializationException e) {
153 | printInternalError("audioTrackInitializationError", e);
154 | }
155 |
156 | @Override
157 | public void onAudioTrackWriteError(AudioTrack.WriteException e) {
158 | printInternalError("audioTrackWriteError", e);
159 | }
160 |
161 | @Override
162 | public void onAudioTrackUnderrun(int bufferSize, long bufferSizeMs, long elapsedSinceLastFeedMs) {
163 | printInternalError("audioTrackUnderrun [" + bufferSize + ", " + bufferSizeMs + ", "
164 | + elapsedSinceLastFeedMs + "]", null);
165 | }
166 |
167 | @Override
168 | public void onCryptoError(CryptoException e) {
169 | printInternalError("cryptoError", e);
170 | }
171 |
172 | @Override
173 | public void onDecoderInitialized(String decoderName, long elapsedRealtimeMs,
174 | long initializationDurationMs) {
175 | Log.d(TAG, "decoderInitialized [" + getSessionTimeString() + ", " + decoderName + "]");
176 | }
177 |
178 | @Override
179 | public void onAvailableRangeChanged(int sourceId, TimeRange availableRange) {
180 | availableRangeValuesUs = availableRange.getCurrentBoundsUs(availableRangeValuesUs);
181 | Log.d(TAG, "availableRange [" + availableRange.isStatic() + ", " + availableRangeValuesUs[0]
182 | + ", " + availableRangeValuesUs[1] + "]");
183 | }
184 |
185 | private void printInternalError(String type, Exception e) {
186 | Log.e(TAG, "internalError [" + getSessionTimeString() + ", " + type + "]", e);
187 | }
188 |
189 | private String getStateString(int state) {
190 | switch (state) {
191 | case ExoPlayer.STATE_BUFFERING:
192 | return "B";
193 | case ExoPlayer.STATE_ENDED:
194 | return "E";
195 | case ExoPlayer.STATE_IDLE:
196 | return "I";
197 | case ExoPlayer.STATE_PREPARING:
198 | return "P";
199 | case ExoPlayer.STATE_READY:
200 | return "R";
201 | default:
202 | return "?";
203 | }
204 | }
205 |
206 | private String getSessionTimeString() {
207 | return getTimeString(SystemClock.elapsedRealtime() - sessionStartTimeMs);
208 | }
209 |
210 | private String getTimeString(long timeMs) {
211 | return TIME_FORMAT.format((timeMs) / 1000f);
212 | }
213 |
214 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------
/library/src/main/java/io/gresse/hugo/simpleexoplayer/player/base/DemoPlayer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package io.gresse.hugo.simpleexoplayer.player.base;
17 |
18 | import android.media.MediaCodec.CryptoException;
19 | import android.os.Handler;
20 | import android.os.Looper;
21 | import android.view.Surface;
22 |
23 | import com.google.android.exoplayer.CodecCounters;
24 | import com.google.android.exoplayer.DummyTrackRenderer;
25 | import com.google.android.exoplayer.ExoPlaybackException;
26 | import com.google.android.exoplayer.ExoPlayer;
27 | import com.google.android.exoplayer.MediaCodecAudioTrackRenderer;
28 | import com.google.android.exoplayer.MediaCodecTrackRenderer;
29 | import com.google.android.exoplayer.MediaCodecVideoTrackRenderer;
30 | import com.google.android.exoplayer.MediaFormat;
31 | import com.google.android.exoplayer.TimeRange;
32 | import com.google.android.exoplayer.TrackRenderer;
33 | import com.google.android.exoplayer.audio.AudioTrack;
34 | import com.google.android.exoplayer.chunk.ChunkSampleSource;
35 | import com.google.android.exoplayer.chunk.Format;
36 | import com.google.android.exoplayer.dash.DashChunkSource;
37 | import com.google.android.exoplayer.drm.StreamingDrmSessionManager;
38 | import com.google.android.exoplayer.hls.HlsSampleSource;
39 | import com.google.android.exoplayer.metadata.MetadataTrackRenderer;
40 | import com.google.android.exoplayer.metadata.id3.Id3Frame;
41 | import com.google.android.exoplayer.text.Cue;
42 | import com.google.android.exoplayer.text.TextRenderer;
43 | import com.google.android.exoplayer.upstream.BandwidthMeter;
44 | import com.google.android.exoplayer.upstream.DefaultBandwidthMeter;
45 | import com.google.android.exoplayer.util.DebugTextViewHelper;
46 | import com.google.android.exoplayer.util.PlayerControl;
47 |
48 | import java.io.IOException;
49 | import java.util.Collections;
50 | import java.util.List;
51 | import java.util.concurrent.CopyOnWriteArrayList;
52 |
53 | /**
54 | * A wrapper around {@link ExoPlayer} that provides a higher level interface. It can be prepared
55 | * with one of a number of {@link RendererBuilder} classes to suit different use cases (e.g. DASH,
56 | * SmoothStreaming and so on).
57 | */
58 | public class DemoPlayer implements ExoPlayer.Listener, ChunkSampleSource.EventListener,
59 | HlsSampleSource.EventListener, DefaultBandwidthMeter.EventListener,
60 | MediaCodecVideoTrackRenderer.EventListener, MediaCodecAudioTrackRenderer.EventListener,
61 | StreamingDrmSessionManager.EventListener, DashChunkSource.EventListener, TextRenderer,
62 | MetadataTrackRenderer.MetadataRenderer
79 | * A canceled build operation must not invoke {@link DemoPlayer#onRenderers} or
80 | * {@link DemoPlayer#onRenderersError} on the player, which may have been released.
81 | */
82 | void cancel();
83 | }
84 |
85 | /**
86 | * A listener for core events.
87 | */
88 | public interface Listener {
89 | void onStateChanged(boolean playWhenReady, int playbackState);
90 | void onError(Exception e);
91 | void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees,
92 | float pixelWidthHeightRatio);
93 | }
94 |
95 | /**
96 | * A listener for internal errors.
97 | *
98 | * These errors are not visible to the user, and hence this listener is provided for
99 | * informational purposes only. Note however that an internal error may cause a fatal
100 | * error if the player fails to recover. If this happens, {@link Listener#onError(Exception)}
101 | * will be invoked.
102 | */
103 | public interface InternalErrorListener {
104 | void onRendererInitializationError(Exception e);
105 | void onAudioTrackInitializationError(AudioTrack.InitializationException e);
106 | void onAudioTrackWriteError(AudioTrack.WriteException e);
107 | void onAudioTrackUnderrun(int bufferSize, long bufferSizeMs, long elapsedSinceLastFeedMs);
108 | void onDecoderInitializationError(MediaCodecTrackRenderer.DecoderInitializationException e);
109 | void onCryptoError(CryptoException e);
110 | void onLoadError(int sourceId, IOException e);
111 | void onDrmSessionManagerError(Exception e);
112 | }
113 |
114 | /**
115 | * A listener for debugging information.
116 | */
117 | public interface InfoListener {
118 | void onVideoFormatEnabled(Format format, int trigger, long mediaTimeMs);
119 | void onAudioFormatEnabled(Format format, int trigger, long mediaTimeMs);
120 | void onDroppedFrames(int count, long elapsed);
121 | void onBandwidthSample(int elapsedMs, long bytes, long bitrateEstimate);
122 | void onLoadStarted(int sourceId, long length, int type, int trigger, Format format,
123 | long mediaStartTimeMs, long mediaEndTimeMs);
124 | void onLoadCompleted(int sourceId, long bytesLoaded, int type, int trigger, Format format,
125 | long mediaStartTimeMs, long mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs);
126 | void onDecoderInitialized(String decoderName, long elapsedRealtimeMs,
127 | long initializationDurationMs);
128 | void onAvailableRangeChanged(int sourceId, TimeRange availableRange);
129 | }
130 |
131 | /**
132 | * A listener for receiving notifications of timed text.
133 | */
134 | public interface CaptionListener {
135 | void onCues(List>, DebugTextViewHelper.Provider {
63 |
64 | /**
65 | * Builds renderers for the player.
66 | */
67 | public interface RendererBuilder {
68 | /**
69 | * Builds renderers for playback.
70 | *
71 | * @param player The player for which renderers are being built. {@link DemoPlayer#onRenderers}
72 | * should be invoked once the renderers have been built. If building fails,
73 | * {@link DemoPlayer#onRenderersError} should be invoked.
74 | */
75 | void buildRenderers(DemoPlayer player);
76 | /**
77 | * Cancels the current build operation, if there is one. Else does nothing.
78 | *