diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000000000000000000000000000000000000..30aa626c23142d59e94cc76327172301f159b618 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000000000000000000000000000000000..7bfef59df1ca77948220ecd36b0f19f148ab7914 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000000000000000000000000000000000..7a089c16951f8191a92cc77581e2d8869ae98de7 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000000000000000000000000000000000000..7f68460d8b38ac04e3a3224d7c79ef719b1991a9 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..8dada3edaf50dbc082c9a125058f25def75e625a --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + 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. diff --git a/README.md b/README.md index 18e9f2ee429bb993daddf55f98b7fe37508d12ca..72ecc8ed99c64cc377e800b75c9a9f73d8dd1fed 100644 --- a/README.md +++ b/README.md @@ -1,37 +1,103 @@ -# ctyun-xstore-player-android +# VideoView -#### 介绍 -ctyun-xstore-player-android +VideoView是一个基于[ijkplayer](https://github.com/Bilibili/ijkplayer)的视屏播放库,可以用于播放本地和网络视频。 -#### 软件架构 -软件架构说明 +一、集成步骤: +第一步: +clone工程到本地,git地址:git@gitee.com:keijack/ctyun-xstore-player-android.git +第二步: +在你自己的工程里面,引入“player”这个module。具体操作,Android Studio,File--New--Import Module,选择clone下来的工程的player模块。 -#### 安装教程 -1. xxxx -2. xxxx -3. xxxx +二、使用说明: -#### 使用说明 +第一步:把VideoView作为一个控件添加到你的布局中: -1. xxxx -2. xxxx -3. xxxx + -#### 参与贡献 +第二步:在AndroidManifest.xml中activity进行如下配置: -1. Fork 本仓库 -2. 新建 Feat_xxx 分支 -3. 提交代码 -4. 新建 Pull Request + -#### 码云特技 -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. 码云官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解码云上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是码云最有价值开源项目,是码云综合评定出的优秀开源项目 -5. 码云官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. 码云封面人物是一档用来展示码云会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) \ No newline at end of file + +第三步:设置播放器高度、设置播放源,即可按照默认配置播放视频了。 + + mVideoView = findViewById(R.id.player); + + // 第1步:设置播放器的高度,一般宽高比16:9;也可以把高度写死在xml配置文件 + int widthPixels = getResources().getDisplayMetrics().widthPixels; + mVideoView.setLayoutParams(new LinearLayout.LayoutParams(widthPixels, widthPixels / 16 * 9)); + + // 可选:播放器相关配置,其他配置参照类PlayerConfig + mVideoView.setPlayerConfig(new PlayerConfig.Builder() + .autoRotate() // 自动旋转屏幕 + .enableMediaCodec() // 启动硬解码 + .savingProgress() // 保存播放进度 + .build()); + + // 可选:设置暂停广告 + mVideoView.setPauseAd(pauseAdUrl); + + // 第2步:必选:设置播放源 + List videos = new ArrayList<>(); + videos.add(new VideoModel(URL_AD, "片头广告", Constants.VIDEO_TYPE_START_AD, new AdControllerListener() { + @Override + public void onAdClick() { + Toast.makeText(DemoActivity.this, "广告点击跳转", Toast.LENGTH_SHORT).show(); + } + })); + videos.add(new VideoModel(URL_VOD, "这是一个标题", Constants.VIDEO_TYPE_VOD)); + videos.add(new VideoModel(URL_AD, "片尾广告", Constants.VIDEO_TYPE_END_AD)); + + // 可选:设置播放器id + mVideoView.setVideoId("asdasdasdads"); + // 可选:设置海报 + mVideoView.setThumbUrl(pauseAdUrl); + mVideoView.setVideos(videos); + // 可选:启用弹幕 + mVideoView.enableDanmaku(); + // 可选:启用投屏 + mVideoView.enableDLNA(); + // 可选:是否自动播放 + mVideoView.start(); + +第四步:在Activity中 + +@Override + protected void onPause() { + super.onPause(); + ijkVideoView.pause(); + } + + @Override + protected void onResume() { + super.onResume(); + ijkVideoView.resume(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + ijkVideoView.release(); + } + + + @Override + public void onBackPressed() { + if (!ijkVideoView.onBackPressed()) { + super.onBackPressed(); + } + } + +================================================================ +播放器其他接口使用,参照DemoActivity.java里面的测试代码 + + diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..9c8a20d939b7596855fe0a3217ccdfd9745e2aad --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,108 @@ +apply plugin: 'com.android.application' + +static def releaseTime() { + return new Date().format("yyyy_MM_dd", TimeZone.getTimeZone("UTC")) +} + +android { + compileSdkVersion rootProject.ext.compileSdkVersion + buildToolsVersion rootProject.ext.buildToolsVersion + + defaultConfig { + applicationId "cn.ctyun.player" + minSdkVersion rootProject.ext.minSdkVersion + targetSdkVersion rootProject.ext.targetSdkVersion + versionCode 29 + versionName "2.5.5" +// multiDexEnabled true + + ndk { + //打包时保留armeabi-v7a x86 so + abiFilters "armeabi-v7a", "x86" + } + } + + sourceSets { + main { + jniLibs.srcDirs = ['libs'] + } + } + + + signingConfigs { + release { + storeFile file("../devlin.jks") + storePassword KEYSTORE_PWD + keyAlias KEY_ALIAS + keyPassword KEY_PWD + } + } + + lintOptions { + checkReleaseBuilds false + // Or, if you prefer, you can continue to check for errors in release builds, + // but continue the build even when errors are found: + abortOnError false + } + + + buildTypes { + debug { + signingConfig signingConfigs.release + zipAlignEnabled false + minifyEnabled false + shrinkResources false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + + release { + signingConfig signingConfigs.release + zipAlignEnabled true + minifyEnabled true + shrinkResources true + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + + applicationVariants.all { variant -> + variant.outputs.all { output -> + outputFileName = "${variant.name}-${variant.versionName}-${releaseTime()}(${variant.versionCode}).apk" + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + packagingOptions { + exclude 'META-INF/DEPENDENCIES.txt' + exclude 'META-INF/NOTICE' + exclude 'META-INF/NOTICE.txt' + exclude 'META-INF/LICENSE' + exclude 'META-INF/LICENSE.txt' + exclude 'META-INF/beans.xml' + } + +} + +dependencies { + implementation fileTree(include: ['*.jar'], dir: 'libs') + debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.2' + releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.2' + debugImplementation 'com.squareup.leakcanary:leakcanary-support-fragment:1.6.2' + implementation "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion" +// implementation 'com.github.bumptech.glide:glide:3.7.0' + implementation 'com.yanzhenjie:permission:2.0.0-rc12' +// implementation 'com.github.ctiao:DanmakuFlameMaster:0.8.3' +// implementation 'com.github.ctiao:DanmakuFlameMaster:0.6.2' +// implementation 'com.github.ctiao:ndkbitmap-armv7a:0.8.3' + implementation "com.android.support:design:$rootProject.supportLibraryVersion" +// implementation 'com.google.android.exoplayer:exoplayer:2.8.2' +// implementation 'com.google.android.exoplayer:extension-rtmp:2.8.2' + //缓存 +// implementation 'com.danikula:videocache:2.7.1' + + + implementation project(':player') + +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000000000000000000000000000000000000..83838b4929e17c8ff1796c52b3a3ddf43b2d2cc0 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,37 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in D:\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 name 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 name. +#-renamesourcefileattribute SourceFile + +-keep class tv.danmaku.ijk.** { *; } +-dontwarn tv.danmaku.ijk.** +-keep class cn.ctyun.videoplayer.** { *; } +-dontwarn cn.ctyun.videoplayer.** + + +-dontwarn com.yanzhenjie.permission.** + +-keep class android.support.** { *; } + +-keep class com.bumptech.glide.** { *; } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000000000000000000000000000000000000..136831ac6d42b7eeafda9fff70b035684eee9ce6 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/assets/test.mp4 b/app/src/main/assets/test.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..46c077249e3bddb2a4a681cc8ee904435623a37e Binary files /dev/null and b/app/src/main/assets/test.mp4 differ diff --git a/app/src/main/ic_launcher-web.png b/app/src/main/ic_launcher-web.png new file mode 100644 index 0000000000000000000000000000000000000000..32b9cd8ce4d8256bcb3aa479af960e03289575f9 Binary files /dev/null and b/app/src/main/ic_launcher-web.png differ diff --git a/app/src/main/java/cn/ctyun/player/activity/DemoActivity.java b/app/src/main/java/cn/ctyun/player/activity/DemoActivity.java new file mode 100644 index 0000000000000000000000000000000000000000..a4a6d8caaca3e32cb6a81a9705a20aa4f134d1af --- /dev/null +++ b/app/src/main/java/cn/ctyun/player/activity/DemoActivity.java @@ -0,0 +1,239 @@ +package cn.ctyun.player.activity; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.view.MenuItem; +import android.view.View; +import android.widget.LinearLayout; +import android.widget.Toast; + +import cn.ctyun.player.R; +import cn.ctyun.videoplayer.bean.VideoModel; +import cn.ctyun.videoplayer.interf.AdControllerListener; +import cn.ctyun.videoplayer.player.PlayerConfig; +import cn.ctyun.videoplayer.util.Constants; +import cn.ctyun.videoplayer.util.MemoryLeakUtil; +import cn.ctyun.videoplayer.widget.VideoView; + +import java.util.ArrayList; +import java.util.List; + +/** + * 弹幕+广告播放 + * Created by devlin on 17-6-11. + */ + +public class DemoActivity extends AppCompatActivity{ + private static final String TAG = "CHL_" + DemoActivity.class.getSimpleName(); + + private VideoView mVideoView; + private static final String URL_VOD = "http://mov.bn.netease.com/open-movie/nos/flv/2017/01/03/SC8U8K7BC_hd.flv"; + // private static final String URL_VOD = "http://baobab.wdjcdn.com/14564977406580.mp4"; + // private static final String URL_VOD = "http://uploads.cutv.com:8088/video/data/201703/10/encode_file/515b6a95601ba6b39620358f2677a17358c2472411d53.mp4"; + private static final String URL_AD = "https://gslb.miaopai.com/stream/IR3oMYDhrON5huCmf7sHCfnU5YKEkgO2.mp4"; + private static final String URL_M3U8 = "http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8"; + private static final String m3u8test = "http://192.168.0.140:8000/oceans/master.m3u8"; + + private static final String LIVE_URL = "http://ivi.bupt.edu.cn/hls/cctv6.m3u8"; + + String pauseAdUrl = "http://s305.photo.store.qq.com/psb?/V10eAGEV1otPhC/kBAaz7ARkoq*denFUikaEZO12W2Ij7FLSK5w0P08vA4!/b/dDEBAAAAAAAA&bo=0gHaANIB2gACkLQ!&_abc=.gif"; + String pauseAdUrl2 = "https://www.ctyun.cn/gw/cms/material/icon/GetByFileId?fileId=153423425195474944"; + String pauseAdUrl3 = "https://www.ctyun.cn/gw/cms/material/icon/Get?materialId=74079026674665422"; + + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_demo); + + Log.d(TAG, "onCreate"); + + ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { + actionBar.setTitle("Demo"); + actionBar.setDisplayHomeAsUpEnabled(true); + } + + mVideoView = findViewById(R.id.player); + + // 设置播放器的高度 + int widthPixels = getResources().getDisplayMetrics().widthPixels; + mVideoView.setLayoutParams(new LinearLayout.LayoutParams(widthPixels, widthPixels / 16 * 9)); + + // 可选:播放器相关配置,其他配置参照类PlayerConfig + mVideoView.setPlayerConfig(new PlayerConfig.Builder() + .autoRotate() // 自动旋转屏幕 + .enableMediaCodec() // 启动硬解码 + .savingProgress() // 保存播放进度 + .build()); + + // 可选:设置暂停广告 + mVideoView.setPauseAd(pauseAdUrl); + // 设置海报 + mVideoView.setThumbUrl(pauseAdUrl2); + + // 必选:设置播放源 + List videos = new ArrayList<>(); + videos.add(new VideoModel(URL_AD, "片头广告", Constants.VIDEO_TYPE_START_AD, new AdControllerListener() { + @Override + public void onAdClick() { + Toast.makeText(DemoActivity.this, "广告点击跳转", Toast.LENGTH_SHORT).show(); + } + })); + videos.add(new VideoModel(URL_VOD, "这是一个标题", Constants.VIDEO_TYPE_VOD)); + videos.add(new VideoModel(URL_AD, "片尾广告", Constants.VIDEO_TYPE_END_AD)); + + mVideoView.setVideos(videos); + +// mVideoView.setPlayableVideoDuration(10); +// 设置播放器id + mVideoView.setVideoId("asdasdasdads"); + + // 启用弹幕 + mVideoView.enableDanmaku(); + // 启用投屏 + mVideoView.enableDLNA(); + // 自动播放 +// mVideoView.start(); + + } + + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == android.R.id.home) { + finish(); + } + return super.onOptionsItemSelected(item); + } + + @Override + protected void onPause() { + super.onPause(); + mVideoView.pause(); + } + + @Override + protected void onResume() { + super.onResume(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mVideoView.release(); + + MemoryLeakUtil.fixLeak(this); + } + + + @Override + public void onBackPressed() { + if (!mVideoView.onBackPressed()) { + super.onBackPressed(); + } + } + + //-------------------------以下为测试代码---------- + + public void testStart(View view) { + if (mVideoView != null) { + mVideoView.start(); + } + } + + public void testPause(View view) { + if (mVideoView != null) { + mVideoView.pause(); + } + } + + public void testResume(View view) { + if (mVideoView != null) { + mVideoView.resume(); + } + } + + public void testStop(View view) { + if (mVideoView != null) { + mVideoView.stop(); + } + } + + public void testSeekTo(View view) { + if (mVideoView != null) { + mVideoView.seekTo(9000); + } + } + + public void testGetDuration(View view) { + if (mVideoView != null) { + Toast.makeText(this, "当前视频时长:" + mVideoView.getDuration() + "ms", Toast.LENGTH_SHORT).show(); + } + } + + public void testSetSpeed(View view) { + if (mVideoView != null) { + mVideoView.setSpeed(2.0f); + } + } + + public void testGetCurrentPosition(View view) { + if (mVideoView != null) { + Toast.makeText(this, "当前视频播放位置:" + mVideoView.getCurrentPosition() + "ms", Toast.LENGTH_SHORT).show(); + } + } + + public void testIsMute(View view) { + if (mVideoView != null) { + Toast.makeText(this, "是否静音:" + mVideoView.isMute(), Toast.LENGTH_SHORT).show(); + } + } + + public void testSetMute(View view) { + if (mVideoView != null) { + mVideoView.setMute(true); + } + } + + public void testResumeMute(View view) { + if (mVideoView != null) { + mVideoView.setMute(false); + } + } + + public void testEnterFullScreen(View view) { + if (mVideoView != null) { + mVideoView.doStartStopFullScreen(); + } + } + + public void testGetBufferedPercentage(View view) { + if (mVideoView != null) { + Toast.makeText(this, "视频预加载百分百:" + mVideoView.getBufferedPercentage() + "%", Toast.LENGTH_SHORT).show(); + } + } + + public void testStopStartAd(View view) { + if (mVideoView != null) { + mVideoView.stopStartAd(); + } + } + + public void testStopEndAd(View view) { + if (mVideoView != null) { + mVideoView.stopEndAd(); + } + } + + + public void testtest(View view) { + if (mVideoView != null) { + + } + } + +} diff --git a/app/src/main/java/cn/ctyun/player/activity/MainActivity.java b/app/src/main/java/cn/ctyun/player/activity/MainActivity.java new file mode 100644 index 0000000000000000000000000000000000000000..e2158248be479c9e6bb0b09c26474307f9649c0a --- /dev/null +++ b/app/src/main/java/cn/ctyun/player/activity/MainActivity.java @@ -0,0 +1,38 @@ +package cn.ctyun.player.activity; + +import android.Manifest; +import android.content.Intent; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; + +import com.yanzhenjie.permission.AndPermission; + +import cn.ctyun.player.R; + +public class MainActivity extends AppCompatActivity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + AndPermission + .with(this) + .runtime() + .permission(Manifest.permission.WRITE_EXTERNAL_STORAGE) + .onDenied(data -> { + + }) + .onGranted(data -> { + + }) + .start(); + } + + + public void playerDemo(View view) { + startActivity(new Intent(this, DemoActivity.class)); + } +} diff --git a/app/src/main/java/cn/ctyun/player/app/MyApplication.java b/app/src/main/java/cn/ctyun/player/app/MyApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..3744c4cc3146edfb93af2ed60558f9889df852fb --- /dev/null +++ b/app/src/main/java/cn/ctyun/player/app/MyApplication.java @@ -0,0 +1,33 @@ +package cn.ctyun.player.app; + +import android.app.Application; + +import cn.ctyun.player.BuildConfig; +import cn.ctyun.videoplayer.util.L; +import com.squareup.leakcanary.LeakCanary; + +/** + * app + * Created by Devlin_n on 2017/4/22. + */ + +public class MyApplication extends Application{ + + private static MyApplication instance; + + @Override + public void onCreate() { + super.onCreate(); + instance = this; + if (LeakCanary.isInAnalyzerProcess(this)) { + return; + } + LeakCanary.install(this); + //播放器日志 + L.setDebug(BuildConfig.DEBUG); + } + + public static MyApplication getInstance() { + return instance; + } +} diff --git a/app/src/main/res/drawable-hdpi/dlna_icon_close.png b/app/src/main/res/drawable-hdpi/dlna_icon_close.png new file mode 100644 index 0000000000000000000000000000000000000000..2e1b9efd684b49221f64075dd77b8b0eac97e0b7 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/dlna_icon_close.png differ diff --git a/app/src/main/res/drawable-hdpi/dlna_icon_progress.png b/app/src/main/res/drawable-hdpi/dlna_icon_progress.png new file mode 100644 index 0000000000000000000000000000000000000000..12be15ddfc8a93be7be533eeac427e8299a30caa Binary files /dev/null and b/app/src/main/res/drawable-hdpi/dlna_icon_progress.png differ diff --git a/app/src/main/res/drawable-hdpi/dlna_icon_selected.png b/app/src/main/res/drawable-hdpi/dlna_icon_selected.png new file mode 100644 index 0000000000000000000000000000000000000000..35b1619505025dc9ac4fdfaedf1b4ef43bb7b3e8 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/dlna_icon_selected.png differ diff --git a/app/src/main/res/drawable-hdpi/dlna_icon_wifi.png b/app/src/main/res/drawable-hdpi/dlna_icon_wifi.png new file mode 100644 index 0000000000000000000000000000000000000000..54d513b44ede4659aed1bed48ec17bd30175b055 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/dlna_icon_wifi.png differ diff --git a/app/src/main/res/drawable/anim_loading_rotate.xml b/app/src/main/res/drawable/anim_loading_rotate.xml new file mode 100644 index 0000000000000000000000000000000000000000..c69a5abeb68ca05d55f3915a60b6790d36bab666 --- /dev/null +++ b/app/src/main/res/drawable/anim_loading_rotate.xml @@ -0,0 +1,7 @@ + + \ No newline at end of file diff --git a/app/src/main/res/drawable/shape_ad_bg.xml b/app/src/main/res/drawable/shape_ad_bg.xml new file mode 100644 index 0000000000000000000000000000000000000000..fe25ff65918a3c95a09aa22969a6afac864f65f2 --- /dev/null +++ b/app/src/main/res/drawable/shape_ad_bg.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/app/src/main/res/drawable/shape_float_window_background.xml b/app/src/main/res/drawable/shape_float_window_background.xml new file mode 100644 index 0000000000000000000000000000000000000000..b13b8610c9659d881fc40e7915b40fe20a2d8252 --- /dev/null +++ b/app/src/main/res/drawable/shape_float_window_background.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_demo.xml b/app/src/main/res/layout/activity_demo.xml new file mode 100644 index 0000000000000000000000000000000000000000..9d7b1f00c8b5629a437cb0cbc06ee8d22a8ebdcb --- /dev/null +++ b/app/src/main/res/layout/activity_demo.xml @@ -0,0 +1,147 @@ + + + + + +