Repository: JarvanMo/ExoVideoView Branch: master Commit: d53e9442b6cc Files: 71 Total size: 254.5 KB Directory structure: gitextract_igumccg0/ ├── .gitignore ├── LICENSE ├── README.md ├── README_CN.md ├── build.gradle ├── demo/ │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src/ │ ├── androidTest/ │ │ └── java/ │ │ └── com/ │ │ └── jarvanmo/ │ │ └── demo/ │ │ └── ExampleInstrumentedTest.java │ ├── main/ │ │ ├── AndroidManifest.xml │ │ ├── java/ │ │ │ └── com/ │ │ │ └── jarvanmo/ │ │ │ └── demo/ │ │ │ ├── MainActivity.java │ │ │ └── SimpleVideoViewActivity.java │ │ └── res/ │ │ ├── drawable/ │ │ │ ├── ic_arrow_back_white_24dp.xml │ │ │ └── ic_error_white_24dp.xml │ │ ├── layout/ │ │ │ ├── activity_main.xml │ │ │ ├── activity_simple_video_view.xml │ │ │ ├── cutom_view_bottom_landscape.xml │ │ │ ├── cutom_view_top.xml │ │ │ └── cutom_view_top_landscape.xml │ │ └── values/ │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test/ │ └── java/ │ └── com/ │ └── jarvanmo/ │ └── demo/ │ └── ExampleUnitTest.java ├── exoplayerview/ │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src/ │ ├── androidTest/ │ │ └── java/ │ │ └── com/ │ │ └── jarvanmo/ │ │ └── exoplayerview/ │ │ └── ExampleInstrumentedTest.java │ ├── main/ │ │ ├── AndroidManifest.xml │ │ ├── java/ │ │ │ └── com/ │ │ │ └── jarvanmo/ │ │ │ └── exoplayerview/ │ │ │ ├── ads/ │ │ │ │ └── ExoAdsLoader.java │ │ │ ├── extension/ │ │ │ │ └── MultiQualitySelectorAdapter.java │ │ │ ├── gesture/ │ │ │ │ ├── OnVideoGestureChangeListener.java │ │ │ │ └── VideoGesture.java │ │ │ ├── media/ │ │ │ │ ├── EventLogger.java │ │ │ │ ├── ExoMediaSource.java │ │ │ │ ├── MediaSourceCreator.java │ │ │ │ ├── MediaSourceParams.java │ │ │ │ ├── SimpleMediaSource.java │ │ │ │ └── SimpleQuality.java │ │ │ ├── orientation/ │ │ │ │ ├── OnOrientationChangedListener.java │ │ │ │ └── SensorOrientation.java │ │ │ ├── ui/ │ │ │ │ ├── ExoVideoPlaybackControlView.java │ │ │ │ └── ExoVideoView.java │ │ │ ├── util/ │ │ │ │ ├── AndroidUtil.java │ │ │ │ └── Permissions.java │ │ │ └── widget/ │ │ │ ├── BatteryLevelView.java │ │ │ └── BatteryStatusView.java │ │ └── res/ │ │ ├── drawable/ │ │ │ ├── ic_arrow_back_white_24dp.xml │ │ │ ├── ic_error_outline_white_48dp.xml │ │ │ ├── stat_sys_battery.xml │ │ │ └── stat_sys_battery_charge.xml │ │ ├── layout/ │ │ │ ├── exo_playback_controller_bottom.xml │ │ │ ├── exo_playback_controller_bottom_landscape.xml │ │ │ ├── exo_playback_controller_top.xml │ │ │ ├── exo_playback_controller_top_landscape.xml │ │ │ ├── exo_player_quality_selector.xml │ │ │ ├── exo_video_playback_control_view.xml │ │ │ ├── exo_video_view.xml │ │ │ └── item_quality.xml │ │ ├── values/ │ │ │ ├── attrs.xml │ │ │ ├── colors.xml │ │ │ ├── dimens.xml │ │ │ ├── ids.xml │ │ │ └── strings.xml │ │ └── values-zh-rCN/ │ │ └── strings.xml │ └── test/ │ └── java/ │ └── com/ │ └── jarvanmo/ │ └── exoplayerview/ │ └── ExampleUnitTest.java ├── gradle/ │ └── wrapper/ │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── gradlew ├── gradlew.bat └── settings.gradle ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ *.iml .gradle /local.properties /.idea .DS_Store /build /captures .externalNativeBuild tmp.txt ================================================ FILE: LICENSE ================================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================ FILE: README.md ================================================ ![logo](./images/default_art.png) # ExoVideoView ExoVideoView is based on [ExoPlayer](https://github.com/google/ExoPlayer). [中文移步至此](./README_CN.md). ![demo](./images/demo.gif) ### Planning new versions **What's in ExoVideoView** 1.Process AudioFocus automatically. 2.Process its orientation by sensor automatically 3.simple gesture action supported. 4.multiple video quality supported 5.you can add custom views to the default controller. 6.multiple resize-mode supported 7.custom controller supported. 8.change the widget's visibility if you like. ## Using ExoVideoView ### 1.Dependency The easiest way to get started using ExoVideoView is to add it as a gradle dependency. You need to make sure you have the jitpack repositories included in the build.gradle file in the root of your project: ``` allprojects { repositories { ... maven { url 'https://jitpack.io' } } } ``` Next add a gradle compile dependency to the build.gradle file of your app module: ``` implementation 'com.github.JarvanMo:ExoVideoView:2.1.6' ``` ### 2.In Layout Declare ExoVideoView in your layout file as : ```xml ``` ### 3.In Java ExoVideoView provides built-in ```Player``` for convenience,so we can play a video as ```java SimpleMediaSource mediaSource = new SimpleMediaSource(url);//uri also supported videoView.play(mediaSource); videoView.play(mediaSource,where);//play from a particular position ``` Passing a player outside to ExoVideoView: ```java videoView.setPlayer(player); ``` Note:never forget to release ExoPlayer: ```java videoView.releasePlayer(); ``` see details in [demo](). ### 3.Orientation Management The ExoVideoView can handle its orientation by sensor automatically only when ExoVideoVIew has a not-null OrientationListener : ```java videoView.setOrientationListener(orientation -> { if (orientation == SENSOR_PORTRAIT) { //do something } else if (orientation == SENSOR_LANDSCAPE) { //do something } }); ``` > NOTE:When the ExoVideoView handle its orientation automatically,The ExoVideoView will call ```activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE)``` or ```activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);``` if the ```context``` in controller is an Activity. The fullscreen management is the same as orientation management. ### 4.Back Events First,override onKeyDown: ```java @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { return videoView.onKeyDown(keyCode, event); } return super.onKeyDown(keyCode, event); } ``` Then passing a backListener to ExoVideoView: ```java videoView.setBackListener((view, isPortrait) -> { if (isPortrait) { //do something } return false; }); ``` If return value is ```true```, operation will be interrupted.Otherwise,ExoVideoView handle its orientation by itself and ```OrientationLister.onOrientationChange()``` will be caled. ## Advance ### 1.Multi-Quality ExoVideoView also provides a built-in multi-quality selector.The multi-quality selector will be added to ```overlayFrameLayout``` if multi-quality is enabled and ```ExoMediaSource``` are given different qualities in current version. ```java List qualities = new ArrayList<>(); ExoMediaSource.Quality quality =new SimpleQuality(quality,mediaSource.url()); qualities.add(quality); mediaSource.setQualities(qualities); ``` ### 2.Controller Display Mode ```ExoVideoPlaybackController``` are divided into four parts: ``` 1.Top 2.Top Landscape 3.Bottom 4.Bottom Landscape ``` Each of them can be hidden or shown: ```xml app:controller_display_mode="all|none|top|top_landscape|bottom|bottom_landscape" ``` in java: ```java videoView.setControllerDisplayMode(mode); ``` ### 3.Add Custom View To Controller Views can be added to ```ExoVideoPlaybackController``` in java. ```java videoView.addCustomView(ExoVideoPlaybackControlView.CUSTOM_VIEW_TOP, view); videoView.addCustomView(ExoVideoPlaybackControlView.CUSTOM_VIEW_TOP_LANDSCAPE, view); videoView.addCustomView(ExoVideoPlaybackControlView.CUSTOM_VIEW_BOTTOM_LANDSCAPE, view); ``` ### 4.Specifying A custom Layout File Defining your own ```exo_video_playback_control_view.xml``` is useful to customize the layout of ```ExoVideoPlaybackControlView``` throughout your application. It's also possible to customize the layout for asingle instance in a layout file. This is achieved by setting the controller_layout_id attribute on a ```ExoVideoPlaybackControlView```. This will cause the specified layout to be inflated instead of ```code exo_video_playback_control_view.xml``` for only the instance on which the attribute is set. ```xml app:controller_layout_id="@layout/my_controller" ``` ### 5.Change Visibility Sometimes,we may not like the back buttons.So let's hide it: ```java videoView.changeWidgetVisibility(R.id.exo_player_controller_back,View.INVISIBLE); ``` For more widgets you can hide or show,see [IDS_IN_CONTROLLER](./exoplayerview/src/main/res/values/ids.xml). > NOTE:This is a dangerous operation because I don't know what will happen to the UI. ## Others ``` app:controller_background="@android:color/holo_orange_dark" app:use_artwork="true" app:default_artwork="@drawable/default_art" ``` ================================================ FILE: README_CN.md ================================================ ![logo](./images/default_art.png) # ExoVideoView ![demo](./images/demo.gif) ExoVideoView 是一款基于[ExoPlayer](https://github.com/google/ExoPlayer)开发的视频播放器. **ExoVideoView可以做什么** 1.自动处理音频焦点。 2.根据传感器自动处理方向。 3.手势支持。 4.多清晰度选择支持。 5.为控制器添加自定义布局. 6.调整显示大小。 7.自定义controller。 8.支持调整控件的可见性。 ## 使用 ExoVideoView ### 1.依赖 最简单的方式是加入gradle依赖。请确认在工程的build.gradle中添加了JCenter和google()。 ``` allprojects { repositories { ... maven { url 'https://jitpack.io' } } } ``` 然后在你的项目中添加如下代码: ``` implementation 'com.github.JarvanMo:ExoVideoView:2.1.6' ``` ### 2.在xml中定义 在xml中使用 ExoVideoView: ```xml ``` ### 3.在java代码中 ExoVideoView 提供了内建```Player```: ```java SimpleMediaSource mediaSource = new SimpleMediaSource(url);//也支持uri videoView.play(mediaSource); videoView.play(mediaSource,where);//play from a particular position ``` 也可以使用自义的Player: ```java videoView.setPlayer(player); ``` 提示:不要忘记释放ExoPlayer: ```java videoView.releasePlayer(); ``` 详情请移步[demo](). ### 3.方向管理 ExoVideoView 可以自动处理方向问题,前提是为ExoVideoView设置一个OrientationListener: ```java videoView.setOrientationListener(orientation -> { if (orientation == SENSOR_PORTRAIT) { //do something } else if (orientation == SENSOR_LANDSCAPE) { //do something } }); ``` 提示:当ExoVideoView自动处理方向问题时,如果在Controller中的context是Activity,那么系统会调用 ```activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE)``` or ```activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);``` 全屏事件处理也是如此。 ### 4返回管理 首先,重写onKeyDown: ```java @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { return videoView.onKeyDown(keyCode, event); } return super.onKeyDown(keyCode, event); } ``` 为ExoVideoView设置监听: ```java videoView.setBackListener((view, isPortrait) -> { if (isPortrait) { //do something } return false; }); ``` 如果返回值是 ```true```, 系统后续动作会被中断.否则,ExoVideoView会自动处理方向,并且会回调```OrientationLister.onOrientationChange()``` . ## 高级 ### 1.多清晰度支持 ExoVideoView 内置清晰度选择器.如果开启发多清晰度并添加了多清晰度,内置清晰度选择器将被加入```overlayFrameLayout```. ```java List qualities = new ArrayList<>(); ExoMediaSource.Quality quality =new SimpleQuality(quality,mediaSource.url()); qualities.add(quality); mediaSource.setQualities(qualities); ``` ### 2.Controller显示模式 ```ExoVideoPlaybackController``` 被分为四个部分: ``` 1.Top 2.Top Landscape 3.Bottom 4.Bottom Landscape ``` 每一部分都可以被显示或隐藏: ```xml app:controller_display_mode="all|none|top|top_landscape|bottom|bottom_landscape" ``` 在java中: ```java videoView.setControllerDisplayMode(mode); ``` ### 3.为controller添加控件 ```ExoVideoPlaybackController``` 允许在java代码中添加控件. ```java videoView.addCustomView(ExoVideoPlaybackControlView.CUSTOM_VIEW_TOP, view); videoView.addCustomView(ExoVideoPlaybackControlView.CUSTOM_VIEW_TOP_LANDSCAPE, view); videoView.addCustomView(ExoVideoPlaybackControlView.CUSTOM_VIEW_BOTTOM_LANDSCAPE, view); ``` ### 4.使用自定义controller ```exo_video_playback_control_view.xml```是允许自定义的。其中一些属性在```ExoVideoPlaybackControlView```有定义。具体可看源码。 ```xml app:controller_layout_id="@layout/my_controller" ``` ### 5.更改控件可见性 有些时候我们可能不太喜欢返回,所以就让我们隐藏起来吧: ```java videoView.changeWidgetVisibility(R.id.exo_player_controller_back,View.INVISIBLE); ``` 获取更多可隐藏的控件,参看 [ids_in_controller](./exoplayerview/src/main/res/values/ids.xml); > 注意:这么做可能比较危险,我不敢保证隐藏以后的效果。 ## 其他 ``` app:controller_background="@android:color/holo_orange_dark" app:use_artwork="true" app:default_artwork="@drawable/default_art" ``` ================================================ FILE: build.gradle ================================================ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { jcenter() google() } dependencies { classpath 'com.android.tools.build:gradle:4.0.1' // classpath 'com.novoda:bintray-release:0.9.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() google() } } task clean(type: Delete) { delete rootProject.buildDir } ext { compileSdkVersion = 29 buildToolsVersion = "26.0.2" minSdkVersion = 17 targetSdkVersion = 27 androidSupportVersion = '27.1.1' } //tasks.getByPath(":exoplayerview:javadocRelease").enabled = false ================================================ FILE: demo/.gitignore ================================================ /build ================================================ FILE: demo/build.gradle ================================================ apply plugin: 'com.android.application' android { compileSdkVersion rootProject.ext.compileSdkVersion defaultConfig { applicationId "com.jarvanmo.demo" minSdkVersion 17 targetSdkVersion 22 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } lintOptions { abortOnError false } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', { exclude group: 'com.android.support', module: 'support-annotations' }) implementation 'androidx.appcompat:appcompat:1.0.2' implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2' testImplementation 'junit:junit:4.12' implementation project(':exoplayerview') // compile 'com.jarvanmo:exoplayerview:0.0.1' // implementation 'com.google.android.exoplayer:exoplayer:2.7.3' compileOnly 'androidx.recyclerview:recyclerview:1.0.0' } ================================================ FILE: demo/proguard-rules.pro ================================================ # Add project specific ProGuard rules here. # By default, the flags in this file are appended to flags specified # in /home/mo/Android/Sdk/tools/proguard/proguard-android.txt # You can edit the include path and order by changing the proguardFiles # directive in build.gradle. # # For more details, see # http://developer.android.com/guide/developing/tools/proguard.html # Add any project specific keep options here: # If your project uses WebView with JS, uncomment the following # and specify the fully qualified class getDisplayName to the JavaScript interface # class: #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} # Uncomment this to preserve the line number information for # debugging stack traces. #-keepattributes SourceFile,LineNumberTable # If you keep the line number information, uncomment this to # hide the original source file getDisplayName. #-renamesourcefileattribute SourceFile ================================================ FILE: demo/src/androidTest/java/com/jarvanmo/demo/ExampleInstrumentedTest.java ================================================ package com.jarvanmo.demo; import android.content.Context; import androidx.test.InstrumentationRegistry; import androidx.test.runner.AndroidJUnit4; import org.junit.Test; import org.junit.runner.RunWith; import static org.junit.Assert.assertEquals; /** * Instrumentation test, which will execute on an Android device. * * @see Testing documentation */ @RunWith(AndroidJUnit4.class) public class ExampleInstrumentedTest { @Test public void useAppContext() throws Exception { // Context of the app under test. Context appContext = InstrumentationRegistry.getTargetContext(); assertEquals("com.jarvanmo.demo", appContext.getPackageName()); } } ================================================ FILE: demo/src/main/AndroidManifest.xml ================================================ ================================================ FILE: demo/src/main/java/com/jarvanmo/demo/MainActivity.java ================================================ package com.jarvanmo.demo; import android.graphics.Color; import android.os.Build; import android.os.Bundle; import androidx.appcompat.app.AppCompatActivity; import android.text.SpannableString; import android.text.Spanned; import android.text.style.ForegroundColorSpan; import android.view.KeyEvent; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.widget.Button; import com.google.android.exoplayer2.ui.AspectRatioFrameLayout; import com.jarvanmo.exoplayerview.media.ExoMediaSource; import com.jarvanmo.exoplayerview.media.SimpleMediaSource; import com.jarvanmo.exoplayerview.media.SimpleQuality; import com.jarvanmo.exoplayerview.ui.ExoVideoView; import java.util.ArrayList; import java.util.List; import static com.jarvanmo.exoplayerview.orientation.OnOrientationChangedListener.SENSOR_LANDSCAPE; import static com.jarvanmo.exoplayerview.orientation.OnOrientationChangedListener.SENSOR_PORTRAIT; public class MainActivity extends AppCompatActivity { private ExoVideoView videoView; private Button modeFit; private Button modeNone; private Button modeHeight; private Button modeWidth; private Button modeZoom; private View wrapper; private Button play; private View contentView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); contentView = findViewById(R.id.activity_main); videoView = findViewById(R.id.videoView); modeFit = findViewById(R.id.mode_fit); modeNone = findViewById(R.id.mode_none); modeHeight = findViewById(R.id.mode_height); modeWidth = findViewById(R.id.mode_width); modeZoom = findViewById(R.id.mode_zoom); wrapper = findViewById(R.id.wrapper); play = findViewById(R.id.changeMode); videoView.setBackListener((view, isPortrait) -> { if (isPortrait) { finish(); } return false; }); // // videoView.setOrientationListener(orientation -> { if (orientation == SENSOR_PORTRAIT) { changeToPortrait(); } else if (orientation == SENSOR_LANDSCAPE) { changeToLandscape(); } }); // // final SimpleMediaSource mediaSource = new SimpleMediaSource("http://video19.ifeng.com/video07/2013/11/11/281708-102-007-1138.mp4"); // SimpleMediaSource mediaSource = new SimpleMediaSource("https://tungsten.aaplimg.com/VOD/bipbop_adv_example_v2/master.m3u8"); // final SimpleMediaSource mediaSource = new SimpleMediaSource("http://playertest.longtailvideo.com/adaptive/bipbop/gear4/prog_index.m3u8"); // SimpleMediaSource mediaSource = new SimpleMediaSource(" https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_4x3/gear0/prog_index.m3u8"); // SimpleMediaSource mediaSource = new SimpleMediaSource("https://tungsten.aaplimg.com/VOD/bipbop_adv_fmp4_example/master.m3u8"); // SimpleMediaSource mediaSource = new SimpleMediaSource("http://pullhlsbb8f2e48.live.126.net/live/7de213ebb3dc4db2aa2f32f3da0b028d/playlist.m3u8"); // SimpleMediaSource mediaSource = new SimpleMediaSource("http://rotation.vod.zlive.cc/channel/1234.m3u8"); // SimpleMediaSource mediaSource = new SimpleMediaSource("https://media.w3.org/2010/05/sintel/trailer.mp4"); SimpleMediaSource mediaSource = new SimpleMediaSource("http://flv2.bn.netease.com/videolib3/1604/28/fVobI0704/SD/fVobI0704-mobile.mp4"); // SimpleMediaSource mediaSource = new SimpleMediaSource("http://stream1.hnntv.cn/lywsgq/sd/live.m3u8"); mediaSource.setDisplayName("VideoPlaying"); List qualities = new ArrayList<>(); ExoMediaSource.Quality quality; for (int i = 0; i < 6; i++) { SpannableString spannableString = new SpannableString("Quality" + i); if (i % 2 == 0) { ForegroundColorSpan colorSpan = new ForegroundColorSpan(Color.YELLOW); spannableString.setSpan(colorSpan, 0, spannableString.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); } else { ForegroundColorSpan colorSpan = new ForegroundColorSpan(Color.RED); spannableString.setSpan(colorSpan, 0, spannableString.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); } quality = new SimpleQuality(spannableString, mediaSource.uri()); qualities.add(quality); } mediaSource.setQualities(qualities); videoView.play(mediaSource, false); play.setOnClickListener(view -> { videoView.play(mediaSource); play.setVisibility(View.INVISIBLE); }); modeFit.setOnClickListener(v -> videoView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT)); modeWidth.setOnClickListener(v -> videoView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIXED_WIDTH)); modeHeight.setOnClickListener(v -> videoView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIXED_HEIGHT)); modeNone.setOnClickListener(v -> videoView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FILL)); modeZoom.setOnClickListener(v -> videoView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_ZOOM)); } private void changeToPortrait() { WindowManager.LayoutParams attr = getWindow().getAttributes(); // attr.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN); Window window = getWindow(); window.setAttributes(attr); window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); wrapper.setVisibility(View.VISIBLE); } private void changeToLandscape() { WindowManager.LayoutParams lp = getWindow().getAttributes(); // lp.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN; Window window = getWindow(); window.setAttributes(lp); window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); wrapper.setVisibility(View.GONE); } @Override protected void onStart() { super.onStart(); if (Build.VERSION.SDK_INT > 23) { videoView.resume(); } } @Override protected void onResume() { super.onResume(); if ((Build.VERSION.SDK_INT <= 23)) { videoView.resume(); } } @Override public void onPause() { super.onPause(); if (Build.VERSION.SDK_INT <= 23) { videoView.pause(); } } @Override public void onStop() { super.onStop(); if (Build.VERSION.SDK_INT > 23) { videoView.pause(); } } @Override protected void onDestroy() { super.onDestroy(); videoView.releasePlayer(); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { return videoView.onKeyDown(keyCode, event); } return super.onKeyDown(keyCode, event); } } ================================================ FILE: demo/src/main/java/com/jarvanmo/demo/SimpleVideoViewActivity.java ================================================ package com.jarvanmo.demo; import android.content.res.Configuration; import android.graphics.Color; import android.net.Uri; import android.os.Build; import android.os.Bundle; import androidx.appcompat.app.AppCompatActivity; import android.text.SpannableString; import android.text.Spanned; import android.text.style.ForegroundColorSpan; import android.view.KeyEvent; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.CheckBox; import android.widget.Spinner; import android.widget.Toast; import com.jarvanmo.exoplayerview.extension.MultiQualitySelectorAdapter; import com.jarvanmo.exoplayerview.media.ExoMediaSource; import com.jarvanmo.exoplayerview.media.SimpleMediaSource; import com.jarvanmo.exoplayerview.media.SimpleQuality; import com.jarvanmo.exoplayerview.ui.ExoVideoPlaybackControlView; import com.jarvanmo.exoplayerview.ui.ExoVideoView; import java.util.ArrayList; import java.util.List; import static com.jarvanmo.exoplayerview.orientation.OnOrientationChangedListener.SENSOR_LANDSCAPE; import static com.jarvanmo.exoplayerview.orientation.OnOrientationChangedListener.SENSOR_PORTRAIT; public class SimpleVideoViewActivity extends AppCompatActivity { private ExoVideoView videoView; private View wrapper; private final String[] modes = new String[]{"RESIZE_MODE_FIT", "RESIZE_MODE_FIXED_WIDTH" , "RESIZE_MODE_FIXED_HEIGHT", "RESIZE_MODE_FILL", "RESIZE_MODE_ZOOM"}; private Spinner modeSpinner; private ArrayAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_simple_video_view); wrapper = findViewById(R.id.wrapper); initSpinner(); initControllerMode(); initVideoView(); initCustomViews(); } private void initVideoView() { videoView = findViewById(R.id.videoView); videoView.setPortrait(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT); videoView.setBackListener((view, isPortrait) -> { if (isPortrait) { finish(); } return false; }); videoView.setOrientationListener(orientation -> { if (orientation == SENSOR_PORTRAIT) { changeToPortrait(); } else if (orientation == SENSOR_LANDSCAPE) { changeToLandscape(); } }); // videoView.setGestureEnabled(false); // // // SimpleMediaSource mediaSource = new SimpleMediaSource("http://flv2.bn.netease.com/videolib3/1604/28/fVobI0704/SD/fVobI0704-mobile.mp4"); // mediaSource.setDisplayName("Apple HLS"); SimpleMediaSource mediaSource = new SimpleMediaSource("http://vfx.mtime.cn/Video/2019/03/12/mp4/190312083533415853.mp4"); mediaSource.setDisplayName("Apple HLS"); //demo only,not real multi quality, urls are the same actually List qualities = new ArrayList<>(); ExoMediaSource.Quality quality; ForegroundColorSpan colorSpan = new ForegroundColorSpan(Color.YELLOW); SpannableString spannableString = new SpannableString("1080p"); spannableString.setSpan(colorSpan, 0, spannableString.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); quality = new SimpleQuality(spannableString, mediaSource.uri()); qualities.add(quality); spannableString = new SpannableString("720p"); colorSpan = new ForegroundColorSpan(Color.LTGRAY); spannableString.setSpan(colorSpan, 0, spannableString.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); quality = new SimpleQuality(spannableString, mediaSource.uri()); qualities.add(quality); mediaSource.setQualities(qualities); // videoView.changeWidgetVisibility(R.id.exo_player_controller_back,View.INVISIBLE); videoView.setMultiQualitySelectorNavigator(new MultiQualitySelectorAdapter.MultiQualitySelectorNavigator() { @Override public boolean onQualitySelected(ExoMediaSource.Quality quality) { quality.setUri(Uri.parse("https://media.w3.org/2010/05/sintel/trailer.mp4")); return false; } }); videoView.play(mediaSource, false); } private void initSpinner() { modeSpinner = findViewById(R.id.spinner); adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); modeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { videoView.setResizeMode(position); } @Override public void onNothingSelected(AdapterView parent) { } }); adapter.addAll(modes); modeSpinner.setAdapter(adapter); } private void initControllerMode() { CheckBox all = findViewById(R.id.all); CheckBox top = findViewById(R.id.top); CheckBox topLandscape = findViewById(R.id.topLandscape); CheckBox bottom = findViewById(R.id.bottom); CheckBox bottomLandscape = findViewById(R.id.bottomLandscape); CheckBox none = findViewById(R.id.none); findViewById(R.id.applyControllerMode).setOnClickListener(v -> { int mode = ExoVideoPlaybackControlView.CONTROLLER_MODE_NONE; if (all.isChecked()) { mode |= ExoVideoPlaybackControlView.CONTROLLER_MODE_ALL; } if (top.isChecked()) { mode |= ExoVideoPlaybackControlView.CONTROLLER_MODE_TOP; } if (topLandscape.isChecked()) { mode |= ExoVideoPlaybackControlView.CONTROLLER_MODE_TOP_LANDSCAPE; } if (bottom.isChecked()) { mode |= ExoVideoPlaybackControlView.CONTROLLER_MODE_BOTTOM; } if (bottomLandscape.isChecked()) { mode |= ExoVideoPlaybackControlView.CONTROLLER_MODE_BOTTOM_LANDSCAPE; } if (none.isChecked()) { mode |= ExoVideoPlaybackControlView.CONTROLLER_MODE_NONE; } videoView.setControllerDisplayMode(mode); Toast.makeText(SimpleVideoViewActivity.this, "change controller display mode", Toast.LENGTH_SHORT).show(); }); } private void initCustomViews() { findViewById(R.id.addToTop).setOnClickListener(v -> { View view = getLayoutInflater().inflate(R.layout.cutom_view_top, null, false); videoView.addCustomView(ExoVideoPlaybackControlView.CUSTOM_VIEW_TOP, view); }); findViewById(R.id.addToTopLandscape).setOnClickListener(v -> { View view = getLayoutInflater().inflate(R.layout.cutom_view_top_landscape, null, false); videoView.addCustomView(ExoVideoPlaybackControlView.CUSTOM_VIEW_TOP_LANDSCAPE, view); }); findViewById(R.id.addToBottomLandscape).setOnClickListener(v -> { View view = getLayoutInflater().inflate(R.layout.cutom_view_bottom_landscape, null, false); videoView.addCustomView(ExoVideoPlaybackControlView.CUSTOM_VIEW_BOTTOM_LANDSCAPE, view); }); } private void changeToPortrait() { // WindowManager operation is not necessary WindowManager.LayoutParams attr = getWindow().getAttributes(); // attr.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN); Window window = getWindow(); window.setAttributes(attr); window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); wrapper.setVisibility(View.VISIBLE); } private void changeToLandscape() { // WindowManager operation is not necessary WindowManager.LayoutParams lp = getWindow().getAttributes(); // lp.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN; Window window = getWindow(); window.setAttributes(lp); window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); wrapper.setVisibility(View.GONE); } @Override protected void onStart() { super.onStart(); if (Build.VERSION.SDK_INT > 23) { videoView.resume(); } } @Override protected void onResume() { super.onResume(); if ((Build.VERSION.SDK_INT <= 23)) { videoView.resume(); } } @Override public void onPause() { super.onPause(); if (Build.VERSION.SDK_INT <= 23) { videoView.pause(); } } @Override public void onStop() { super.onStop(); if (Build.VERSION.SDK_INT > 23) { videoView.pause(); } } @Override protected void onDestroy() { super.onDestroy(); videoView.releasePlayer(); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { return videoView.onKeyDown(keyCode, event); } return super.onKeyDown(keyCode, event); } } ================================================ FILE: demo/src/main/res/drawable/ic_arrow_back_white_24dp.xml ================================================ ================================================ FILE: demo/src/main/res/drawable/ic_error_white_24dp.xml ================================================ ================================================ FILE: demo/src/main/res/layout/activity_main.xml ================================================