├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── allen │ │ └── supervideoplayer │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── allen │ │ │ └── supervideoplayer │ │ │ ├── App.java │ │ │ ├── MainActivity.java │ │ │ └── VideoPlayerActivity.java │ └── res │ │ ├── layout │ │ ├── activity_main.xml │ │ └── activity_video_player.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 │ │ ├── raw │ │ ├── local_video.mp4 │ │ └── loginvideo.mp4 │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── allen │ └── supervideoplayer │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── playerview ├── .gitignore ├── build.gradle ├── libs │ └── pldroid-player-1.5.1.jar ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── allen │ │ └── playerview │ │ ├── VideoFileUtils.java │ │ └── VideoPlayerView.java │ ├── jniLibs │ ├── arm64-v8a │ │ └── libpldroidplayer.so │ ├── armeabi-v7a │ │ └── libpldroidplayer.so │ ├── armeabi │ │ └── libpldroidplayer.so │ └── x86 │ │ └── libpldroidplayer.so │ └── res │ ├── drawable │ ├── default_seekbar.xml │ └── default_seekbar_thumb.xml │ ├── layout │ └── video_player_view_layout.xml │ ├── mipmap-xhdpi │ ├── default_play_img.png │ ├── default_service_video_dot.png │ ├── default_service_video_play_xiao.png │ ├── default_service_video_suspend.png │ └── default_service_xuanzhuan.png │ ├── mipmap-xxhdpi │ ├── default_play_img.png │ ├── default_service_video_dot.png │ ├── default_service_video_play_xiao.png │ ├── default_service_video_suspend.png │ └── default_service_xuanzhuan.png │ └── values │ ├── attrs.xml │ ├── colors.xml │ └── strings.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | .DS_Store 4 | /build 5 | /captures 6 | ### Android template 7 | # Built application files 8 | *.apk 9 | *.ap_ 10 | 11 | # Files for the ART/Dalvik VM 12 | *.dex 13 | 14 | # Java class files 15 | *.class 16 | 17 | # Generated files 18 | bin/ 19 | gen/ 20 | out/ 21 | 22 | # Gradle files 23 | .gradle/ 24 | build/ 25 | 26 | .idea 27 | # Local configuration file (sdk path, etc) 28 | local.properties 29 | 30 | # Proguard folder generated by Eclipse 31 | proguard/ 32 | 33 | # Log Files 34 | *.log 35 | 36 | # Android Studio Navigation editor temp files 37 | .navigation/ 38 | 39 | # Android Studio captures folder 40 | captures/ 41 | 42 | # Intellij 43 | *.iml 44 | .idea/workspace.xml 45 | .idea/tasks.xml 46 | .idea/gradle.xml 47 | .idea/dictionaries 48 | .idea/libraries 49 | 50 | # Keystore files 51 | *.jks 52 | 53 | # External native build folder generated in Android Studio 2.2 and later 54 | .externalNativeBuild 55 | 56 | # Google Services (e.g. APIs or Firebase) 57 | google-services.json 58 | 59 | # Freeline 60 | freeline.py 61 | freeline/ 62 | freeline_project_description.json 63 | 64 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SuperVideoPlayer 2 | 基于 ijkplayer 和PLDroidPlayer( based on ffplay )二次封装的视频播放器 3 | 4 | 5 | #playerView使用说明 6 | 7 | **1、在XML中使用** 8 | 9 | a、引入VideoPlayerView 10 | 11 | 20 | 21 | 22 | 23 | 24 | b、可配置的所有属性 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | c、参数意义 50 | 51 | /** 52 | * 视频地址 53 | */ 54 | private String videoPath = null; 55 | /** 56 | * 是否自动播放 57 | */ 58 | private boolean isStartVideo = false; 59 | /** 60 | * 是否重复播放 61 | */ 62 | private boolean repeatPlay = false; 63 | /** 64 | * 是否显示底部播放控制布局 65 | */ 66 | private boolean isShowPlayerBottomBar = false; 67 | /** 68 | * 是否显示加载loading 69 | */ 70 | private boolean isShowLoadingView = true; 71 | /** 72 | * 是否显示视频全屏按钮 73 | */ 74 | private boolean isShowFullScreenBtn = false; 75 | /** 76 | * 是否允许点击屏幕暂停播放 77 | */ 78 | private boolean isTouchForPause = true; 79 | 80 | /** 81 | * 是否显示中间视频播放按钮 82 | */ 83 | private boolean isShowCenterPlayerBtn = true; 84 | 85 | /** 86 | * 封面图片 87 | */ 88 | private Drawable coverViewDrawable = null; 89 | /** 90 | * 视频画面预览模式 16:9 4:3 适应屏幕 等等 91 | */ 92 | private int aspectRatio; 93 | 94 | 95 | **2、代码中使用** 96 | 97 | playerView 98 | .setPlayerPath("yourVideoUrl") 99 | .isShowPlayerBottomBar(true) 100 | .isShowLoadingView(true) 101 | .isShowCenterPlayerBtn(true) 102 | .isRepeatPlay(true) 103 | .isTouchForPause(true) 104 | .isShowFullScreenBtn(true) 105 | .setSoundOff() 106 | .setSound(1) 107 | .setScreenRatio(VideoPlayerView.FIT_PARENT) 108 | .setSoundOpen() 109 | .start(); 110 | 111 | 112 | 113 | a、设置视频播放完毕监听回调方法 114 | playerView.setOnVideoCompletionListener(new VideoPlayerView.OnVideoCompletionListener() { 115 | @Override 116 | public void doOnVideoCompletionListener() { 117 | 118 | } 119 | }); 120 | b、设置播放进度回调方法 121 | playerView.setOnCurrentProgressChange(new VideoPlayerView.OnCurrentProgressChange() { 122 | @Override 123 | public void onCurrentProgressChange(int currentProgress, String currentTime) { 124 | 125 | } 126 | }); 127 | 128 | 129 | c、如需要全屏按钮生效需要加上这句代码传递上下文对象 130 | 配合isShowFullScreenBtn(true)使用 131 | playerView.setOnFullScreenClickListener(this); 132 | 133 | 134 | 135 | 136 | **3、如果需要边播变缓存的话需要在application里边添加如下代码( 依赖第三方视频缓存库 compile 'com.danikula:videocache:2.6.4' ) 137 | 具体使用方法可参考 https://github.com/danikula/AndroidVideoCache** 138 | 139 | 140 | private HttpProxyCacheServer proxy; 141 | 142 | 143 | /** 144 | * 视频缓存 145 | * 146 | * @return 147 | */ 148 | public static HttpProxyCacheServer getProxy() { 149 | return sDatingApp.proxy == null ? (sDatingApp.proxy = sDatingApp.newProxy()) : sDatingApp.proxy; 150 | } 151 | 152 | private HttpProxyCacheServer newProxy() { 153 | return new HttpProxyCacheServer(this); 154 | } 155 | 156 | 157 | 在每次传递网络地址的时候使用方法如下 158 | String urlPath = DatingApp.getProxy().getProxyUrl(videoPath);这个方法获取缓存地址 159 | playerView.setPlayerPath(urlPath).start(); 160 | 161 | **4、如有疑问可阅读源码注释** -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.1" 6 | defaultConfig { 7 | applicationId "com.allen.supervideoplayer" 8 | minSdkVersion 15 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile project(':playerview') 28 | compile 'com.android.support:appcompat-v7:25.3.0' 29 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 30 | testCompile 'junit:junit:4.12' 31 | compile 'com.danikula:videocache:2.6.4' 32 | compile 'com.github.lygttpod:SuperTextView:1.1.1' 33 | } 34 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/Allen/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/allen/supervideoplayer/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.allen.supervideoplayer; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.allen.supervideoplayer", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/supervideoplayer/App.java: -------------------------------------------------------------------------------- 1 | package com.allen.supervideoplayer; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | 6 | import com.danikula.videocache.HttpProxyCacheServer; 7 | 8 | /** 9 | * Created by Allen on 2017/4/5. 10 | * 11 | */ 12 | 13 | public class App extends Application { 14 | 15 | private static Context context; 16 | 17 | /** 18 | * 视频缓存类 19 | */ 20 | private HttpProxyCacheServer proxy; 21 | 22 | 23 | @Override 24 | public void onCreate() { 25 | super.onCreate(); 26 | context = getApplicationContext(); 27 | } 28 | 29 | 30 | public static Context getContext() { 31 | return context; 32 | } 33 | 34 | 35 | /** 36 | * 视频缓存 37 | * 38 | * @return 39 | */ 40 | public static HttpProxyCacheServer getProxy() { 41 | App app = (App) context.getApplicationContext(); 42 | return app.proxy == null ? (app.proxy = app.newProxy()) : app.proxy; 43 | } 44 | 45 | private HttpProxyCacheServer newProxy() { 46 | return new HttpProxyCacheServer(this); 47 | } 48 | 49 | 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/supervideoplayer/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.allen.supervideoplayer; 2 | 3 | import android.content.Intent; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | import android.widget.Button; 8 | 9 | public class MainActivity extends AppCompatActivity { 10 | 11 | Button button1, button2; 12 | 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | setContentView(R.layout.activity_main); 17 | 18 | button1 = (Button) findViewById(R.id.button1); 19 | button2 = (Button) findViewById(R.id.button2); 20 | 21 | button1.setOnClickListener(new View.OnClickListener() { 22 | @Override 23 | public void onClick(View v) { 24 | 25 | Intent intent = new Intent(MainActivity.this, VideoPlayerActivity.class); 26 | intent.putExtra("playLocalVideo", false); 27 | startActivity(intent); 28 | } 29 | }); 30 | 31 | button2.setOnClickListener(new View.OnClickListener() { 32 | @Override 33 | public void onClick(View v) { 34 | 35 | Intent intent = new Intent(MainActivity.this, VideoPlayerActivity.class); 36 | intent.putExtra("playLocalVideo", true); 37 | startActivity(intent); 38 | } 39 | }); 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/com/allen/supervideoplayer/VideoPlayerActivity.java: -------------------------------------------------------------------------------- 1 | package com.allen.supervideoplayer; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | import android.view.Window; 6 | import android.view.WindowManager; 7 | 8 | import com.allen.playerview.VideoFileUtils; 9 | import com.allen.playerview.VideoPlayerView; 10 | 11 | public class VideoPlayerActivity extends AppCompatActivity { 12 | 13 | private VideoPlayerView playerView; 14 | 15 | // private String videoUrl = "rtmp://live.hkstv.hk.lxdns.com/live/hks"; 16 | private String videoUrl = "https://ztest3-pic.jikeyue.com/mapi/i/video_exp/micky.mp4?gv=4_1"; 17 | 18 | private String mVideoSuffix = ".mp4"; 19 | 20 | private boolean isPlayLocalVideo = false; 21 | 22 | @Override 23 | protected void onCreate(Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | 26 | setFullScreen(); 27 | 28 | setContentView(R.layout.activity_video_player); 29 | 30 | isPlayLocalVideo = getIntent().getBooleanExtra("playLocalVideo", false); 31 | 32 | playerView = (VideoPlayerView) findViewById(R.id.player_view); 33 | //开启全屏按钮监听事件 34 | playerView.setOnFullScreenClickListener(this); 35 | 36 | if (isPlayLocalVideo) { 37 | String localVideoPath = VideoFileUtils.getCopyRawResToSdcardPath(this, R.raw.loginvideo, mVideoSuffix); 38 | playerView.setPlayerPath(localVideoPath).start(); 39 | } else { 40 | String uriPath = cacheVideo(); 41 | playerView.setPlayerPath(uriPath).start(); 42 | } 43 | } 44 | 45 | /** 46 | * 全屏设置 47 | */ 48 | private void setFullScreen() { 49 | /*set it to be full screen*/ 50 | requestWindowFeature(Window.FEATURE_NO_TITLE); 51 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 52 | WindowManager.LayoutParams.FLAG_FULLSCREEN); 53 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); // 防止锁屏 54 | 55 | } 56 | 57 | /** 58 | * 缓存视频 边播边缓存 59 | * 60 | * @return 61 | */ 62 | private String cacheVideo() { 63 | 64 | return App.getProxy().getProxyUrl(videoUrl); 65 | } 66 | 67 | @Override 68 | protected void onResume() { 69 | super.onResume(); 70 | playerView.onResume(); 71 | } 72 | 73 | @Override 74 | protected void onPause() { 75 | super.onPause(); 76 | playerView.onPause(); 77 | } 78 | 79 | @Override 80 | protected void onDestroy() { 81 | super.onDestroy(); 82 | playerView.onDestroy(); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 |