├── .gitignore ├── .google └── packaging.yaml ├── .idea ├── compiler.xml ├── encodings.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── screenshots └── template-icon.png ├── settings.gradle └── videoplayerapp ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src └── main ├── AndroidManifest.xml ├── java └── com │ └── example │ └── android │ └── videoplayersample │ ├── AudioFocusWrapper.kt │ ├── MediaCatalog.kt │ ├── Player.kt │ └── VideoActivity.kt └── res ├── drawable-v24 └── ic_launcher_foreground.xml ├── drawable ├── ic_launcher_background.xml └── loading.png ├── layout ├── activity_video.xml └── custom_playback_control_minimal.xml ├── mipmap-anydpi-v26 ├── ic_launcher.xml └── ic_launcher_round.xml ├── mipmap-hdpi ├── ic_launcher.png └── ic_launcher_round.png ├── mipmap-mdpi ├── ic_launcher.png └── ic_launcher_round.png ├── mipmap-xhdpi ├── ic_launcher.png └── ic_launcher_round.png ├── mipmap-xxhdpi ├── ic_launcher.png └── ic_launcher_round.png ├── mipmap-xxxhdpi ├── ic_launcher.png └── ic_launcher_round.png └── values ├── colors.xml ├── integers.xml ├── strings.xml └── styles.xml /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/ 38 | 39 | # Keystore files 40 | *.jks 41 | 42 | # External native build folder generated in Android Studio 2.2 and later 43 | .externalNativeBuild 44 | 45 | # Google Services (e.g. APIs or Firebase) 46 | google-services.json 47 | 48 | # Freeline 49 | freeline.py 50 | freeline/ 51 | freeline_project_description.json 52 | -------------------------------------------------------------------------------- /.google/packaging.yaml: -------------------------------------------------------------------------------- 1 | # GOOGLE SAMPLE PACKAGING DATA 2 | # 3 | # This file is used by Google as part of our samples packaging process. 4 | # End users may safely ignore this file. It has no relevance to other systems. 5 | --- 6 | # Values: {DRAFT | PUBLISHED | INTERNAL | DEPRECATED | SUPERCEDED} 7 | status: PUBLISHED 8 | 9 | # Optional, put additional explanation here for DEPRECATED or SUPERCEDED. 10 | # statusNote: 11 | 12 | # See http://go/sample-categories 13 | technologies: [Android, ExoPlayer] 14 | categories: [Media] 15 | languages: [Kotlin] 16 | solutions: [Mobile] 17 | 18 | # May be omitted if unpublished 19 | github: googlesamples/android-VideoPlayer 20 | 21 | # Values: BEGINNER | INTERMEDIATE | ADVANCED | EXPERT 22 | level: INTERMEDIATE 23 | 24 | # Dimensions: 512x512, PNG fomrat 25 | icon: screenshots/template-icon.png 26 | 27 | # List of APIs that this sample should be listed under. Use authoritive, 28 | # names that are unique for the product in question. Examples: 29 | # 30 | # Android - android: 31 | # App Engine - gae-java: 32 | # gae-python: 33 | # Web Services - ws: 34 | apiRefs: 35 | - android:android.support.v4.media.session.MediaSessionCompat 36 | - android:android.app.PictureInPictureParams 37 | - android:com.google.android.exoplayer2.SimpleExoPlayer 38 | - android:com.google.android.exoplayer2.ui.PlayerView 39 | 40 | # Default: apache2. May be omitted for most samples. 41 | # Alternatives: apache2-android (for AOSP) 42 | license: apache2 43 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 36 | 37 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 78 | 79 | 80 | 92 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | Android 112 | 113 | 114 | CorrectnessLintAndroid 115 | 116 | 117 | General 118 | 119 | 120 | Java 121 | 122 | 123 | LintAndroid 124 | 125 | 126 | Performance issuesJava 127 | 128 | 129 | 130 | 131 | Android 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 143 | 144 | 145 | 146 | 147 | android 148 | 149 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 165 | 166 | 167 | 168 | 169 | 170 | Java 171 | 172 | 177 | 178 | 179 | 180 | 181 | 182 | Java 183 | 184 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 211 | 212 | 213 | 214 | 215 | 216 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to become a contributor and submit your own code 2 | 3 | ## Contributor License Agreements 4 | 5 | We'd love to accept your sample apps and patches! Before we can take them, we 6 | have to jump a couple of legal hurdles. 7 | 8 | Please fill out either the individual or corporate Contributor License Agreement (CLA). 9 | 10 | * If you are an individual writing original source code and you're sure you 11 | own the intellectual property, then you'll need to sign an [individual CLA] 12 | (https://cla.developers.google.com). 13 | * If you work for a company that wants to allow you to contribute your work, 14 | then you'll need to sign a [corporate CLA] 15 | (https://cla.developers.google.com). 16 | 17 | Follow either of the two links above to access the appropriate CLA and 18 | instructions for how to sign and return it. Once we receive it, we'll be able to 19 | accept your pull requests. 20 | 21 | ## Contributing A Patch 22 | 23 | 1. Submit an issue describing your proposed change to the repo in question. 24 | 1. The repo owner will respond to your issue promptly. 25 | 1. If your proposed change is accepted, and you haven't already done so, sign a 26 | Contributor License Agreement (see details above). 27 | 1. Fork the desired repo, develop and test your code changes. 28 | 1. Ensure that your code adheres to the existing style in the sample to which 29 | you are contributing. Refer to the 30 | [Android Code Style Guide] 31 | (https://source.android.com/source/code-style.html) for the 32 | recommended coding standards for this organization. 33 | 1. Ensure that your code has an appropriate set of unit tests which all pass. 34 | 1. Submit a pull request. 35 | -------------------------------------------------------------------------------- /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 2018 The Android Open Source Project 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Android Video Player Sample 2 | =========================== 3 | 4 | This repo has been migrated to [github.com/android/media-samples][1]. Please check that repo for future updates. Thank you! 5 | 6 | [1]: https://github.com/android/media-samples 7 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Google LLC. All rights reserved. 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 | 17 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 18 | 19 | buildscript { 20 | ext.kotlin_version = '1.2.30' 21 | repositories { 22 | google() 23 | jcenter() 24 | } 25 | dependencies { 26 | classpath 'com.android.tools.build:gradle:3.0.1' 27 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 28 | 29 | // NOTE: Do not place your application dependencies here; they belong 30 | // in the individual module build.gradle files 31 | } 32 | } 33 | 34 | allprojects { 35 | repositories { 36 | google() 37 | jcenter() 38 | } 39 | } 40 | 41 | task clean(type: Delete) { 42 | delete rootProject.buildDir 43 | } 44 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2018 Google LLC. All rights reserved. 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 | 17 | # Project-wide Gradle settings. 18 | 19 | # IDE (e.g. Android Studio) users: 20 | # Gradle settings configured through the IDE *will override* 21 | # any settings specified in this file. 22 | 23 | # For more details on how to configure your build environment visit 24 | # http://www.gradle.org/docs/current/userguide/build_environment.html 25 | 26 | # Specifies the JVM arguments used for the daemon process. 27 | # The setting is particularly useful for tweaking memory settings. 28 | org.gradle.jvmargs=-Xmx1536m 29 | 30 | # When configured, Gradle will run in incubating parallel mode. 31 | # This option should only be used with decoupled projects. More details, visit 32 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 33 | # org.gradle.parallel=true 34 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-VideoPlayer/14898c2271bfb53be8d9ab250f2107a28ec20ac5/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2018 Google LLC. All rights reserved. 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 | 17 | #Wed Jan 17 11:08:27 PST 2018 18 | distributionBase=GRADLE_USER_HOME 19 | distributionPath=wrapper/dists 20 | zipStoreBase=GRADLE_USER_HOME 21 | zipStorePath=wrapper/dists 22 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip 23 | -------------------------------------------------------------------------------- /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 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /screenshots/template-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-VideoPlayer/14898c2271bfb53be8d9ab250f2107a28ec20ac5/screenshots/template-icon.png -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Google LLC. All rights reserved. 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 | 17 | include ':videoplayerapp' 18 | -------------------------------------------------------------------------------- /videoplayerapp/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /videoplayerapp/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Google LLC. All rights reserved. 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 | 17 | apply plugin: 'com.android.application' 18 | apply plugin: 'kotlin-android' 19 | apply plugin: 'kotlin-android-extensions' 20 | 21 | android { 22 | compileSdkVersion 27 23 | defaultConfig { 24 | applicationId "com.example.android.videoplayersample" 25 | minSdkVersion 21 26 | targetSdkVersion 27 27 | versionCode 1 28 | versionName "1.0" 29 | } 30 | } 31 | 32 | ext { 33 | exoplayer_version = "2.7.0" 34 | supportlib_version = "27.1.0" 35 | anko_version = "0.10.4" 36 | } 37 | 38 | dependencies { 39 | // Kotlin 40 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" 41 | 42 | // ExoPlayer v2 43 | implementation "com.google.android.exoplayer:exoplayer-core:$exoplayer_version" 44 | implementation "com.google.android.exoplayer:exoplayer-ui:$exoplayer_version" 45 | 46 | // ExoPlayer v2 MediaSession extension 47 | implementation "com.google.android.exoplayer:extension-mediasession:$exoplayer_version" 48 | 49 | // Material Design Components 50 | implementation "com.android.support:design:$supportlib_version" 51 | implementation "com.android.support:appcompat-v7:$supportlib_version" 52 | 53 | // Anko 54 | implementation "org.jetbrains.anko:anko:$anko_version" 55 | 56 | } 57 | -------------------------------------------------------------------------------- /videoplayerapp/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /videoplayerapp/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 16 | 18 | 19 | 20 | 21 | 28 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /videoplayerapp/src/main/java/com/example/android/videoplayersample/AudioFocusWrapper.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Google LLC. All rights reserved. 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 | 17 | package com.example.android.videoplayersample 18 | 19 | import android.annotation.TargetApi 20 | import android.media.AudioAttributes 21 | import android.media.AudioFocusRequest 22 | import android.media.AudioManager 23 | import android.os.Build 24 | import android.support.annotation.RequiresApi 25 | import android.support.v4.media.AudioAttributesCompat 26 | import com.google.android.exoplayer2.ExoPlayer 27 | import com.google.android.exoplayer2.SimpleExoPlayer 28 | import org.jetbrains.anko.AnkoLogger 29 | import org.jetbrains.anko.warn 30 | 31 | /** 32 | * Wrapper around a [SimpleExoPlayer] simplifies playback by automatically handling 33 | * audio focus using [AudioFocusRequest] on Oreo+ devices, and an 34 | * [AudioManager.OnAudioFocusChangeListener] on previous versions. 35 | */ 36 | class AudioFocusWrapper(private val audioAttributes: AudioAttributesCompat, 37 | private val audioManager: AudioManager, 38 | private val player: SimpleExoPlayer) : ExoPlayer by player, AnkoLogger { 39 | private var shouldPlayWhenReady = false 40 | 41 | private val audioFocusListener = AudioManager.OnAudioFocusChangeListener { focusChange -> 42 | when (focusChange) { 43 | AudioManager.AUDIOFOCUS_GAIN -> { 44 | if (shouldPlayWhenReady || player.playWhenReady) { 45 | player.playWhenReady = true 46 | player.volume = MEDIA_VOLUME_DEFAULT 47 | } 48 | shouldPlayWhenReady = false 49 | } 50 | AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK -> { 51 | if (player.playWhenReady) { 52 | player.volume = MEDIA_VOLUME_DUCK 53 | } 54 | } 55 | AudioManager.AUDIOFOCUS_LOSS_TRANSIENT -> { 56 | shouldPlayWhenReady = player.playWhenReady 57 | player.playWhenReady = false 58 | } 59 | AudioManager.AUDIOFOCUS_LOSS -> { 60 | abandonAudioFocus() 61 | } 62 | } 63 | } 64 | 65 | @get:RequiresApi(Build.VERSION_CODES.O) 66 | private val audioFocusRequest by lazy { buildFocusRequest() } 67 | 68 | override fun setPlayWhenReady(playWhenReady: Boolean) { 69 | if (playWhenReady) requestAudioFocus() else abandonAudioFocus() 70 | } 71 | 72 | private fun requestAudioFocus() { 73 | val result = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 74 | requestAudioFocusOreo() 75 | } else { 76 | @Suppress("deprecation") 77 | audioManager.requestAudioFocus(audioFocusListener, 78 | audioAttributes.legacyStreamType, 79 | AudioManager.AUDIOFOCUS_GAIN) 80 | } 81 | 82 | // Call the listener whenever focus is granted - even the first time! 83 | if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { 84 | shouldPlayWhenReady = true 85 | audioFocusListener.onAudioFocusChange(AudioManager.AUDIOFOCUS_GAIN) 86 | } else { 87 | warn { "Playback not started: Audio focus request denied" } 88 | } 89 | } 90 | 91 | private fun abandonAudioFocus() { 92 | player.playWhenReady = false 93 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 94 | abandonAudioFocusOreo() 95 | } else { 96 | @Suppress("deprecation") 97 | audioManager.abandonAudioFocus(audioFocusListener) 98 | } 99 | } 100 | 101 | @RequiresApi(Build.VERSION_CODES.O) 102 | private fun requestAudioFocusOreo(): Int = audioManager.requestAudioFocus(audioFocusRequest) 103 | 104 | @RequiresApi(Build.VERSION_CODES.O) 105 | private fun abandonAudioFocusOreo() = audioManager.abandonAudioFocusRequest(audioFocusRequest) 106 | 107 | @TargetApi(Build.VERSION_CODES.O) 108 | private fun buildFocusRequest(): AudioFocusRequest = 109 | AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN) 110 | .setAudioAttributes(audioAttributes.unwrap() as? AudioAttributes) 111 | .setOnAudioFocusChangeListener(audioFocusListener) 112 | .build() 113 | } 114 | 115 | private const val MEDIA_VOLUME_DEFAULT = 1.0f 116 | private const val MEDIA_VOLUME_DUCK = 0.2f -------------------------------------------------------------------------------- /videoplayerapp/src/main/java/com/example/android/videoplayersample/MediaCatalog.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Google LLC. All rights reserved. 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 | 17 | package com.example.android.videoplayersample 18 | 19 | import android.net.Uri 20 | import android.support.v4.media.MediaDescriptionCompat 21 | 22 | /** 23 | * Manages a set of media metadata that is used to create a playlist for [VideoActivity]. 24 | */ 25 | 26 | open class MediaCatalog(private val list: MutableList) : 27 | List by list { 28 | 29 | companion object : MediaCatalog(mutableListOf()) 30 | 31 | init { 32 | // More creative commons, creative commons videos - https://www.blender.org/about/projects/ 33 | list.add( 34 | with(MediaDescriptionCompat.Builder()) { 35 | setDescription("MP4 loaded over HTTP") 36 | setMediaId("1") 37 | // License - https://peach.blender.org/download/ 38 | setMediaUri(Uri.parse("http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4")) 39 | setTitle("Short film Big Buck Bunny") 40 | setSubtitle("Streaming video") 41 | build() 42 | }) 43 | list.add( 44 | with(MediaDescriptionCompat.Builder()) { 45 | setDescription("MP4 loaded over HTTP") 46 | setMediaId("2") 47 | // License - https://archive.org/details/ElephantsDream 48 | setMediaUri(Uri.parse("https://archive.org/download/ElephantsDream/ed_hd.mp4")) 49 | setTitle("Short film Elephants Dream") 50 | setSubtitle("Streaming video") 51 | build() 52 | }) 53 | list.add( 54 | with(MediaDescriptionCompat.Builder()) { 55 | setDescription("MOV loaded over HTTP") 56 | setMediaId("3") 57 | // License - https://mango.blender.org/sharing/ 58 | setMediaUri(Uri.parse("http://ftp.nluug.nl/pub/graphics/blender/demo/movies/ToS/ToS-4k-1920.mov")) 59 | setTitle("Short film Tears of Steel") 60 | setSubtitle("Streaming audio") 61 | build() 62 | }) 63 | } 64 | } -------------------------------------------------------------------------------- /videoplayerapp/src/main/java/com/example/android/videoplayersample/Player.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Google LLC. All rights reserved. 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 | 17 | package com.example.android.videoplayersample 18 | 19 | import android.content.Context 20 | import android.media.AudioManager 21 | import android.net.Uri 22 | import android.support.v4.media.AudioAttributesCompat 23 | import com.google.android.exoplayer2.ExoPlaybackException 24 | import com.google.android.exoplayer2.ExoPlayer 25 | import com.google.android.exoplayer2.ExoPlayerFactory 26 | import com.google.android.exoplayer2.Player 27 | import com.google.android.exoplayer2.source.ConcatenatingMediaSource 28 | import com.google.android.exoplayer2.source.ExtractorMediaSource 29 | import com.google.android.exoplayer2.source.MediaSource 30 | import com.google.android.exoplayer2.trackselection.DefaultTrackSelector 31 | import com.google.android.exoplayer2.ui.PlayerView 32 | import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory 33 | import org.jetbrains.anko.AnkoLogger 34 | import org.jetbrains.anko.info 35 | import org.jetbrains.anko.toast 36 | 37 | /** 38 | * Creates and manages a [com.google.android.exoplayer2.ExoPlayer] instance. 39 | */ 40 | 41 | data class PlayerState(var window: Int = 0, 42 | var position: Long = 0, 43 | var whenReady: Boolean = true) 44 | 45 | class PlayerHolder(private val context: Context, 46 | private val playerState: PlayerState, 47 | private val playerView: PlayerView) : AnkoLogger { 48 | val audioFocusPlayer: ExoPlayer 49 | 50 | // Create the player instance. 51 | init { 52 | val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager 53 | val audioAttributes = AudioAttributesCompat.Builder() 54 | .setContentType(AudioAttributesCompat.CONTENT_TYPE_MUSIC) 55 | .setUsage(AudioAttributesCompat.USAGE_MEDIA) 56 | .build() 57 | audioFocusPlayer = AudioFocusWrapper( 58 | audioAttributes, 59 | audioManager, 60 | ExoPlayerFactory.newSimpleInstance(context, DefaultTrackSelector()) 61 | .also { playerView.player = it } 62 | ) 63 | info { "SimpleExoPlayer created" } 64 | } 65 | 66 | private fun buildMediaSource(): MediaSource { 67 | val uriList = mutableListOf() 68 | MediaCatalog.forEach { 69 | uriList.add(createExtractorMediaSource(it.mediaUri!!)) 70 | } 71 | return ConcatenatingMediaSource(*uriList.toTypedArray()) 72 | } 73 | 74 | private fun createExtractorMediaSource(uri: Uri): MediaSource { 75 | return ExtractorMediaSource.Factory( 76 | DefaultDataSourceFactory(context, "exoplayer-learning")) 77 | .createMediaSource(uri) 78 | } 79 | 80 | // Prepare playback. 81 | fun start() { 82 | // Load media. 83 | audioFocusPlayer.prepare(buildMediaSource()) 84 | // Restore state (after onResume()/onStart()) 85 | with(playerState) { 86 | // Start playback when media has buffered enough 87 | // (whenReady is true by default). 88 | audioFocusPlayer.playWhenReady = whenReady 89 | audioFocusPlayer.seekTo(window, position) 90 | // Add logging. 91 | attachLogging(audioFocusPlayer) 92 | } 93 | info { "SimpleExoPlayer is started" } 94 | } 95 | 96 | // Stop playback and release resources, but re-use the player instance. 97 | fun stop() { 98 | with(audioFocusPlayer) { 99 | // Save state 100 | with(playerState) { 101 | position = currentPosition 102 | window = currentWindowIndex 103 | whenReady = playWhenReady 104 | } 105 | // Stop the player (and release it's resources). The player instance can be reused. 106 | stop(true) 107 | } 108 | info { "SimpleExoPlayer is stopped" } 109 | } 110 | 111 | // Destroy the player instance. 112 | fun release() { 113 | audioFocusPlayer.release() // player instance can't be used again. 114 | info { "SimpleExoPlayer is released" } 115 | } 116 | 117 | /** 118 | * For more info on ExoPlayer logging, please review this 119 | * [codelab](https://codelabs.developers.google.com/codelabs/exoplayer-intro/#5). 120 | */ 121 | private fun attachLogging(exoPlayer: ExoPlayer) { 122 | // Show toasts on state changes. 123 | exoPlayer.addListener(object : Player.DefaultEventListener() { 124 | override fun onPlayerStateChanged(playWhenReady: Boolean, playbackState: Int) { 125 | when (playbackState) { 126 | Player.STATE_ENDED -> { 127 | context.toast(R.string.msg_playback_ended) 128 | } 129 | Player.STATE_READY -> when (playWhenReady) { 130 | true -> { 131 | context.toast(R.string.msg_playback_started) 132 | } 133 | false -> { 134 | context.toast(R.string.msg_playback_paused) 135 | } 136 | } 137 | } 138 | } 139 | }) 140 | // Write to log on state changes. 141 | exoPlayer.addListener(object : Player.DefaultEventListener() { 142 | override fun onPlayerStateChanged(playWhenReady: Boolean, playbackState: Int) { 143 | info { "playerStateChanged: ${getStateString(playbackState)}, $playWhenReady" } 144 | } 145 | 146 | override fun onPlayerError(error: ExoPlaybackException?) { 147 | info { "playerError: $error" } 148 | } 149 | 150 | fun getStateString(state: Int): String { 151 | return when (state) { 152 | Player.STATE_BUFFERING -> "STATE_BUFFERING" 153 | Player.STATE_ENDED -> "STATE_ENDED" 154 | Player.STATE_IDLE -> "STATE_IDLE" 155 | Player.STATE_READY -> "STATE_READY" 156 | else -> "?" 157 | } 158 | } 159 | }) 160 | 161 | } 162 | 163 | } -------------------------------------------------------------------------------- /videoplayerapp/src/main/java/com/example/android/videoplayersample/VideoActivity.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Google LLC. All rights reserved. 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 | 17 | package com.example.android.videoplayersample 18 | 19 | import android.app.PictureInPictureParams 20 | import android.content.res.Configuration 21 | import android.media.AudioManager 22 | import android.os.Build 23 | import android.os.Bundle 24 | import android.support.v4.media.MediaDescriptionCompat 25 | import android.support.v4.media.session.MediaSessionCompat 26 | import android.support.v7.app.AppCompatActivity 27 | import android.util.Rational 28 | import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector 29 | import com.google.android.exoplayer2.ext.mediasession.TimelineQueueNavigator 30 | import kotlinx.android.synthetic.main.activity_video.* 31 | import org.jetbrains.anko.AnkoLogger 32 | 33 | /** 34 | * Allows playback of videos that are in a playlist, using [PlayerHolder] to load the and render 35 | * it to the [com.google.android.exoplayer2.ui.PlayerView] to render the video output. Supports 36 | * [MediaSessionCompat] and picture in picture as well. 37 | */ 38 | 39 | class VideoActivity : AppCompatActivity(), AnkoLogger { 40 | private val mediaSession: MediaSessionCompat by lazy { createMediaSession() } 41 | private val mediaSessionConnector: MediaSessionConnector by lazy { 42 | createMediaSessionConnector() 43 | } 44 | private val playerState by lazy { PlayerState() } 45 | private lateinit var playerHolder: PlayerHolder 46 | 47 | // Android lifecycle hooks. 48 | override fun onCreate(savedInstanceState: Bundle?) { 49 | super.onCreate(savedInstanceState) 50 | setContentView(R.layout.activity_video) 51 | // While the user is in the app, the volume controls should adjust the music volume. 52 | volumeControlStream = AudioManager.STREAM_MUSIC 53 | createMediaSession() 54 | createPlayer() 55 | } 56 | 57 | override fun onStart() { 58 | super.onStart() 59 | startPlayer() 60 | activateMediaSession() 61 | } 62 | 63 | override fun onStop() { 64 | super.onStop() 65 | stopPlayer() 66 | deactivateMediaSession() 67 | } 68 | 69 | override fun onDestroy() { 70 | super.onDestroy() 71 | releasePlayer() 72 | releaseMediaSession() 73 | } 74 | 75 | // MediaSession related functions. 76 | private fun createMediaSession(): MediaSessionCompat = MediaSessionCompat(this, packageName) 77 | 78 | private fun createMediaSessionConnector(): MediaSessionConnector = 79 | MediaSessionConnector(mediaSession).apply { 80 | // If QueueNavigator isn't set, then mediaSessionConnector will not handle following 81 | // MediaSession actions (and they won't show up in the minimized PIP activity): 82 | // [ACTION_SKIP_PREVIOUS], [ACTION_SKIP_NEXT], [ACTION_SKIP_TO_QUEUE_ITEM] 83 | setQueueNavigator(object : TimelineQueueNavigator(mediaSession) { 84 | override fun getMediaDescription(windowIndex: Int): MediaDescriptionCompat { 85 | return MediaCatalog[windowIndex] 86 | } 87 | }) 88 | } 89 | 90 | 91 | // MediaSession related functions. 92 | private fun activateMediaSession() { 93 | // Note: do not pass a null to the 3rd param below, it will cause a NullPointerException. 94 | // To pass Kotlin arguments to Java varargs, use the Kotlin spread operator `*`. 95 | mediaSessionConnector.setPlayer(playerHolder.audioFocusPlayer, null) 96 | mediaSession.isActive = true 97 | } 98 | 99 | private fun deactivateMediaSession() { 100 | mediaSessionConnector.setPlayer(null, null) 101 | mediaSession.isActive = false 102 | } 103 | 104 | private fun releaseMediaSession() { 105 | mediaSession.release() 106 | } 107 | 108 | // ExoPlayer related functions. 109 | private fun createPlayer() { 110 | playerHolder = PlayerHolder(this, playerState, exoplayerview_activity_video) 111 | } 112 | 113 | private fun startPlayer() { 114 | playerHolder.start() 115 | } 116 | 117 | private fun stopPlayer() { 118 | playerHolder.stop() 119 | } 120 | 121 | private fun releasePlayer() { 122 | playerHolder.release() 123 | } 124 | 125 | // Picture in Picture related functions. 126 | override fun onUserLeaveHint() { 127 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 128 | enterPictureInPictureMode( 129 | with(PictureInPictureParams.Builder()) { 130 | val width = 16 131 | val height = 9 132 | setAspectRatio(Rational(width, height)) 133 | build() 134 | }) 135 | } 136 | } 137 | 138 | override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean, 139 | newConfig: Configuration?) { 140 | exoplayerview_activity_video.useController = !isInPictureInPictureMode 141 | } 142 | 143 | } -------------------------------------------------------------------------------- /videoplayerapp/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 23 | 28 | 29 | 35 | 38 | 41 | 42 | 43 | 44 | 50 | 51 | -------------------------------------------------------------------------------- /videoplayerapp/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 23 | 26 | 31 | 36 | 41 | 46 | 51 | 56 | 61 | 66 | 71 | 76 | 81 | 86 | 91 | 96 | 101 | 106 | 111 | 116 | 121 | 126 | 131 | 136 | 141 | 146 | 151 | 156 | 161 | 166 | 171 | 176 | 181 | 186 | 187 | -------------------------------------------------------------------------------- /videoplayerapp/src/main/res/drawable/loading.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-VideoPlayer/14898c2271bfb53be8d9ab250f2107a28ec20ac5/videoplayerapp/src/main/res/drawable/loading.png -------------------------------------------------------------------------------- /videoplayerapp/src/main/res/layout/activity_video.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 30 | -------------------------------------------------------------------------------- /videoplayerapp/src/main/res/layout/custom_playback_control_minimal.xml: -------------------------------------------------------------------------------- 1 | 16 | 23 | 24 | 30 | 31 | 37 | 38 | 45 | 46 | 53 | 54 | 60 | 61 | 62 | 63 | 69 | 70 | 81 | 82 | 87 | 88 | 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /videoplayerapp/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /videoplayerapp/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /videoplayerapp/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-VideoPlayer/14898c2271bfb53be8d9ab250f2107a28ec20ac5/videoplayerapp/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /videoplayerapp/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-VideoPlayer/14898c2271bfb53be8d9ab250f2107a28ec20ac5/videoplayerapp/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /videoplayerapp/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-VideoPlayer/14898c2271bfb53be8d9ab250f2107a28ec20ac5/videoplayerapp/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /videoplayerapp/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-VideoPlayer/14898c2271bfb53be8d9ab250f2107a28ec20ac5/videoplayerapp/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /videoplayerapp/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-VideoPlayer/14898c2271bfb53be8d9ab250f2107a28ec20ac5/videoplayerapp/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /videoplayerapp/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-VideoPlayer/14898c2271bfb53be8d9ab250f2107a28ec20ac5/videoplayerapp/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /videoplayerapp/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-VideoPlayer/14898c2271bfb53be8d9ab250f2107a28ec20ac5/videoplayerapp/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /videoplayerapp/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-VideoPlayer/14898c2271bfb53be8d9ab250f2107a28ec20ac5/videoplayerapp/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /videoplayerapp/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-VideoPlayer/14898c2271bfb53be8d9ab250f2107a28ec20ac5/videoplayerapp/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /videoplayerapp/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/android-VideoPlayer/14898c2271bfb53be8d9ab250f2107a28ec20ac5/videoplayerapp/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /videoplayerapp/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | #5daef1 20 | #5096cf 21 | #ff4081 22 | #CC000000 23 | #cc63c866 24 | #ccc76185 25 | #cca2a2a2 26 | 27 | -------------------------------------------------------------------------------- /videoplayerapp/src/main/res/values/integers.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 5000 20 | 10000 21 | 10000 22 | -------------------------------------------------------------------------------- /videoplayerapp/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | A Simple VideoPlayer 19 | playback ended 20 | playback started 21 | playback paused 22 | 23 | -------------------------------------------------------------------------------- /videoplayerapp/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 24 | 25 | 29 | 30 |