├── .github └── ISSUE_TEMPLATE │ ├── -------.md │ ├── ----.md │ └── bug_report.md ├── .gitignore ├── LICENSE ├── README.md ├── app ├── build.gradle ├── jzvd-keystore ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── assets │ ├── jzvd.html │ └── local_video.mp4 │ ├── ic_launcher-web.png │ ├── java │ └── cn │ │ └── jzvd │ │ └── demo │ │ ├── ActivityApi.java │ │ ├── ActivityApiCustomMedia.java │ │ ├── ActivityApiExtendsNormal.java │ │ ├── ActivityApiOrientation.java │ │ ├── ActivityApiRotationVideoSize.java │ │ ├── ActivityApiUIBigChange.java │ │ ├── ActivityApiUISmallChange.java │ │ ├── ActivityDirectPlay.java │ │ ├── ActivityListView.java │ │ ├── ActivityListViewFragmentViewPager.java │ │ ├── ActivityListViewMultiHolder.java │ │ ├── ActivityListViewNormal.java │ │ ├── ActivityListViewRecyclerView.java │ │ ├── ActivityMain.java │ │ ├── ActivityPreloading.java │ │ ├── ActivityPreloadingList.java │ │ ├── ActivityTinyWindow.java │ │ ├── ActivityTinyWindowRecycleView.java │ │ ├── ActivityTinyWindowRecycleViewMultiHolder.java │ │ ├── ActivityWebView.java │ │ ├── AdapterListView.java │ │ ├── AdapterRecyclerView.java │ │ ├── AdapterRecyclerViewTiny.java │ │ ├── ApplicationDemo.java │ │ ├── CustomJzvd │ │ ├── JzvdStdAutoCompleteAfterFullscreen.java │ │ ├── JzvdStdList.java │ │ ├── JzvdStdMp3.java │ │ ├── JzvdStdShowShareButtonAfterFullscreen.java │ │ ├── JzvdStdShowTextureViewAfterAutoComplete.java │ │ ├── JzvdStdShowTitleAfterFullscreen.java │ │ ├── JzvdStdSpeed.java │ │ ├── JzvdStdTinyWindow.java │ │ ├── JzvdStdVolumeAfterFullscreen.java │ │ └── MyJzvdStd.java │ │ ├── CustomMedia │ │ ├── JZMediaExo.java │ │ ├── JZMediaIjk.java │ │ └── JZMediaSystemAssertFolder.java │ │ ├── FragmentDemo.java │ │ └── VideoConstant.java │ └── res │ ├── drawable │ ├── share_selector.xml │ ├── skin_enlarge_video.png │ ├── skin_seek_progress.xml │ └── skin_shrink_video.png │ ├── layout │ ├── activity_api.xml │ ├── activity_api_custom_mediaplayer.xml │ ├── activity_api_rotation_videosize.xml │ ├── activity_auto_tiny.xml │ ├── activity_auto_tiny_list.xml │ ├── activity_directly_play.xml │ ├── activity_extends_normal.xml │ ├── activity_listview.xml │ ├── activity_listview_normal.xml │ ├── activity_listview_viewpager.xml │ ├── activity_main.xml │ ├── activity_orientation.xml │ ├── activity_preloading.xml │ ├── activity_recyclerview_content.xml │ ├── activity_tiny_window.xml │ ├── activity_ui_big_change.xml │ ├── activity_ui_small_change.xml │ ├── activity_webview.xml │ ├── header_auto_tiny_normal.xml │ ├── item_textview.xml │ ├── item_videoview.xml │ ├── item_videoview_tiny.xml │ ├── jz_layout_standard_mp3.xml │ ├── layout_list.xml │ ├── layout_std_speed.xml │ └── layout_std_with_share_button.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ ├── share_normal.png │ └── share_pressed.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle ├── maven_push.gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── jiaozivideoplayer ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── cn │ │ └── jzvd │ │ ├── JZDataSource.java │ │ ├── JZMediaInterface.java │ │ ├── JZMediaSystem.java │ │ ├── JZTextureView.java │ │ ├── JZUtils.java │ │ ├── Jzvd.java │ │ └── JzvdStd.java │ └── res │ ├── drawable-xhdpi │ ├── jz_add_volume.png │ ├── jz_back_normal.png │ ├── jz_back_pressed.png │ ├── jz_back_tiny_normal.png │ ├── jz_back_tiny_pressed.png │ ├── jz_backward_icon.png │ ├── jz_battery_level_10.png │ ├── jz_battery_level_100.png │ ├── jz_battery_level_30.png │ ├── jz_battery_level_50.png │ ├── jz_battery_level_70.png │ ├── jz_battery_level_90.png │ ├── jz_brightness_video.png │ ├── jz_clarity_popwindow_bg.9.png │ ├── jz_close_volume.png │ ├── jz_enlarge.png │ ├── jz_forward_icon.png │ ├── jz_loading_bg.png │ ├── jz_pause_normal.png │ ├── jz_pause_pressed.png │ ├── jz_play_normal.png │ ├── jz_play_pressed.png │ ├── jz_restart_normal.png │ ├── jz_restart_pressed.png │ ├── jz_share_normal.png │ ├── jz_share_pressed.png │ ├── jz_shrink.png │ └── jz_volume_icon.png │ ├── drawable-xxhdpi │ └── jz_clarity_popwindow_bg.9.png │ ├── drawable │ ├── jz_bottom_bg.9.png │ ├── jz_bottom_progress.xml │ ├── jz_bottom_seek_progress.xml │ ├── jz_bottom_seek_thumb.xml │ ├── jz_click_back_selector.xml │ ├── jz_click_back_tiny_selector.xml │ ├── jz_click_pause_selector.xml │ ├── jz_click_play_selector.xml │ ├── jz_click_replay_selector.xml │ ├── jz_click_share_selector.xml │ ├── jz_dialog_progress.xml │ ├── jz_dialog_progress_bg.xml │ ├── jz_loading.xml │ ├── jz_seek_thumb_normal.xml │ ├── jz_seek_thumb_pressed.xml │ ├── jz_title_bg.9.png │ ├── jz_volume_progress_bg.xml │ └── retry_bg.xml │ ├── layout │ ├── jz_dialog_brightness.xml │ ├── jz_dialog_progress.xml │ ├── jz_dialog_volume.xml │ ├── jz_layout_clarity.xml │ ├── jz_layout_clarity_item.xml │ └── jz_layout_std.xml │ ├── values-es │ └── strings.xml │ ├── values-ja-rJP │ └── strings.xml │ ├── values-ko-rKR │ └── strings.xml │ ├── values-pt │ └── strings.xml │ ├── values-tr │ └── strings.xml │ ├── values-zh │ └── strings.xml │ ├── values │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml │ └── xml │ └── jz_network_security_config.xml └── settings.gradle /.github/ISSUE_TEMPLATE/-------.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 此需求如何实现 3 | about: 需求描述 4 | 5 | --- 6 | 7 | **需求描述 8 | 9 | **其他app是否实现 10 | 11 | **截图或者小视频说明 12 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/----.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 我的需求 3 | about: 需求描述 4 | 5 | --- 6 | 7 | **需求描述 8 | 9 | **其他app是否实现 10 | 11 | **截图或者小视频说明 12 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | 5 | --- 6 | 7 | **什么jzvd版本 8 | 9 | **是否和安卓版本有关系,什么版本 10 | 11 | **是否和特定品牌的手机机型有关系,什么机型 12 | 13 | **相关log是什么 14 | 15 | **复现流程 16 | 17 | **最好有截图或者视频说明情况 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /infer-out 2 | gradle.properties 3 | *.iml 4 | .gradle 5 | /local.properties 6 | .idea 7 | .DS_Store 8 | build 9 | /captures 10 | *.asc 11 | projectFilesBackup 12 | release 13 | _build -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015-2018 李盼 Nathen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

JiaoZiVideoPlayer

2 | -- 3 | 4 | Move to [Jzvd/JiaoZiVideoPlayer](https://github.com/Jzvd/JiaoZiVideoPlayer) 5 | 6 | Highly customizable Android video framework 7 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | 6 | defaultConfig { 7 | applicationId "cn.jzvd.demo" 8 | minSdkVersion 16 9 | targetSdkVersion 28 10 | versionCode 93 11 | versionName "7.0.5" 12 | } 13 | signingConfigs { 14 | releaseConfig { 15 | storeFile file("jzvd-keystore") 16 | storePassword "123456" 17 | keyAlias "key0" 18 | keyPassword "123456" 19 | } 20 | } 21 | buildTypes { 22 | // debug {//测试时会用到 23 | // minifyEnabled true 24 | // proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 25 | // signingConfig signingConfigs.releaseConfig 26 | // } 27 | release { 28 | minifyEnabled true 29 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 30 | signingConfig signingConfigs.releaseConfig 31 | } 32 | } 33 | compileOptions { 34 | sourceCompatibility 1.8 35 | targetCompatibility 1.8 36 | } 37 | lintOptions { 38 | abortOnError false 39 | } 40 | } 41 | 42 | dependencies { 43 | implementation fileTree(include: ['*.jar'], dir: 'libs') 44 | testImplementation 'junit:junit:4.12' 45 | implementation 'com.android.support:appcompat-v7:28.0.0' 46 | implementation project(':jiaozivideoplayer') 47 | implementation 'tv.danmaku.ijk.media:ijkplayer-java:0.8.8' 48 | implementation 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.8.4' 49 | implementation 'com.android.support:recyclerview-v7:28.0.0' 50 | implementation 'com.danikula:videocache:2.7.0' 51 | implementation 'com.github.bumptech.glide:glide:4.7.1' 52 | implementation 'com.google.android.exoplayer:exoplayer:2.9.1' 53 | } 54 | -------------------------------------------------------------------------------- /app/jzvd-keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lipangit/JiaoZiVideoPlayer/3db479b1a816965336fa5884708037a0a2971c33/app/jzvd-keystore -------------------------------------------------------------------------------- /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/Nathen/WorkEnv/android-sdk-macosx/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 | -keep public class cn.jzvd.JZMediaSystem {*; } 20 | -keep public class cn.jzvd.demo.CustomMedia.CustomMedia {*; } 21 | -keep public class cn.jzvd.demo.CustomMedia.JZMediaIjk {*; } 22 | -keep public class cn.jzvd.demo.CustomMedia.JZMediaSystemAssertFolder {*; } 23 | 24 | 25 | -keep class tv.danmaku.ijk.media.player.** {*; } 26 | -dontwarn tv.danmaku.ijk.media.player.* 27 | -keep interface tv.danmaku.ijk.media.player.** { *; } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 17 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /app/src/main/assets/jzvd.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 |
6 |
7 |
8 |

This is webview

9 |
10 |
11 |
12 |
13 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/assets/local_video.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lipangit/JiaoZiVideoPlayer/3db479b1a816965336fa5884708037a0a2971c33/app/src/main/assets/local_video.mp4 -------------------------------------------------------------------------------- /app/src/main/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lipangit/JiaoZiVideoPlayer/3db479b1a816965336fa5884708037a0a2971c33/app/src/main/ic_launcher-web.png -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/ActivityApi.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo; 2 | 3 | import android.content.Intent; 4 | import android.content.pm.PackageManager; 5 | import android.hardware.Sensor; 6 | import android.hardware.SensorManager; 7 | import android.os.Bundle; 8 | import android.os.Environment; 9 | import android.support.annotation.Nullable; 10 | import android.support.v4.app.ActivityCompat; 11 | import android.support.v7.app.AppCompatActivity; 12 | import android.view.MenuItem; 13 | import android.view.View; 14 | import android.widget.Toast; 15 | 16 | import com.bumptech.glide.Glide; 17 | 18 | import java.io.FileOutputStream; 19 | import java.io.IOException; 20 | import java.io.InputStream; 21 | import java.io.OutputStream; 22 | import java.util.LinkedHashMap; 23 | 24 | import cn.jzvd.JZDataSource; 25 | import cn.jzvd.Jzvd; 26 | import cn.jzvd.JzvdStd; 27 | 28 | /** 29 | * Created by Nathen on 16/7/31. 30 | */ 31 | public class ActivityApi extends AppCompatActivity { 32 | JzvdStd mJzvdStd; 33 | Jzvd.JZAutoFullscreenListener mSensorEventListener; 34 | SensorManager mSensorManager; 35 | 36 | @Override 37 | protected void onCreate(@Nullable Bundle savedInstanceState) { 38 | super.onCreate(savedInstanceState); 39 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 40 | getSupportActionBar().setDisplayShowHomeEnabled(true); 41 | getSupportActionBar().setDisplayShowTitleEnabled(true); 42 | getSupportActionBar().setDisplayUseLogoEnabled(false); 43 | getSupportActionBar().setTitle("Api"); 44 | setContentView(R.layout.activity_api); 45 | 46 | mJzvdStd = findViewById(R.id.jz_video); 47 | LinkedHashMap map = new LinkedHashMap(); 48 | String proxyUrl = ApplicationDemo.getProxy(this).getProxyUrl(VideoConstant.videoUrls[0][9]); 49 | map.put("高清", proxyUrl); 50 | map.put("标清", VideoConstant.videoUrls[0][6]); 51 | map.put("普清", VideoConstant.videoUrlList[0]); 52 | JZDataSource jzDataSource = new JZDataSource(map, "饺子不信"); 53 | jzDataSource.looping = true; 54 | jzDataSource.currentUrlIndex = 2; 55 | jzDataSource.headerMap.put("key", "value");//header 56 | mJzvdStd.setUp(jzDataSource 57 | , JzvdStd.SCREEN_NORMAL); 58 | Glide.with(this).load(VideoConstant.videoThumbList[0]).into(mJzvdStd.thumbImageView); 59 | // mJzvdStd.seekToInAdvance = 20000; 60 | // Jzvd.SAVE_PROGRESS = false;//把这些注释的代码放到按钮上,让它可操作可见。 61 | 62 | /** Play video in local path, eg:record by system camera **/ 63 | // cpAssertVideoToLocalPath(); 64 | // mJzvdStd.setUp(Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/Camera/local_video.mp4" 65 | // , "饺子不信", Jzvd.SCREEN_NORMAL); 66 | mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); 67 | mSensorEventListener = new Jzvd.JZAutoFullscreenListener(); 68 | } 69 | 70 | @Override 71 | protected void onResume() { 72 | super.onResume(); 73 | Sensor accelerometerSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); 74 | mSensorManager.registerListener(mSensorEventListener, accelerometerSensor, SensorManager.SENSOR_DELAY_NORMAL); 75 | //home back 76 | Jzvd.goOnPlayOnResume(); 77 | } 78 | 79 | @Override 80 | protected void onPause() { 81 | super.onPause(); 82 | mSensorManager.unregisterListener(mSensorEventListener); 83 | Jzvd.clearSavedProgress(this, null); 84 | //home back 85 | Jzvd.goOnPlayOnPause(); 86 | } 87 | 88 | @Override 89 | public void onBackPressed() { 90 | if (Jzvd.backPress()) { 91 | return; 92 | } 93 | super.onBackPressed(); 94 | } 95 | 96 | @Override 97 | public boolean onOptionsItemSelected(MenuItem item) { 98 | switch (item.getItemId()) { 99 | case android.R.id.home: 100 | finish(); 101 | break; 102 | } 103 | return super.onOptionsItemSelected(item); 104 | } 105 | 106 | public void cpAssertVideoToLocalPath() { 107 | verifyStoragePermissions(); 108 | try { 109 | InputStream myInput; 110 | OutputStream myOutput = new FileOutputStream(Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/Camera/local_video.mp4"); 111 | myInput = this.getAssets().open("local_video.mp4"); 112 | byte[] buffer = new byte[1024]; 113 | int length = myInput.read(buffer); 114 | while (length > 0) { 115 | myOutput.write(buffer, 0, length); 116 | length = myInput.read(buffer); 117 | } 118 | 119 | myOutput.flush(); 120 | myInput.close(); 121 | myOutput.close(); 122 | } catch (IOException e) { 123 | e.printStackTrace(); 124 | } 125 | } 126 | 127 | 128 | public void verifyStoragePermissions() { 129 | try { 130 | int permission = ActivityCompat.checkSelfPermission(this, 131 | "android.permission.WRITE_EXTERNAL_STORAGE"); 132 | if (permission != PackageManager.PERMISSION_GRANTED) { 133 | ActivityCompat.requestPermissions(this, new String[]{ 134 | "android.permission.READ_EXTERNAL_STORAGE", 135 | "android.permission.WRITE_EXTERNAL_STORAGE"}, 1); 136 | } 137 | } catch (Exception e) { 138 | e.printStackTrace(); 139 | } 140 | } 141 | 142 | public void clickSmallChange(View view) { 143 | startActivity(new Intent(ActivityApi.this, ActivityApiUISmallChange.class)); 144 | } 145 | 146 | public void clickBigChange(View view) { 147 | Toast.makeText(ActivityApi.this, "Comming Soon", Toast.LENGTH_SHORT).show(); 148 | // startActivity(new Intent(ActivityApi.this, ActivityApiUIBigChange.class)); 149 | } 150 | 151 | public void clickOrientation(View view) { 152 | startActivity(new Intent(ActivityApi.this, ActivityApiOrientation.class)); 153 | 154 | } 155 | 156 | public void clickExtendsNormalActivity(View view) { 157 | startActivity(new Intent(ActivityApi.this, ActivityApiExtendsNormal.class)); 158 | } 159 | 160 | public void clickRotationAndVideoSize(View view) { 161 | startActivity(new Intent(ActivityApi.this, ActivityApiRotationVideoSize.class)); 162 | } 163 | 164 | public void clickCustomMediaPlayer(View view) { 165 | startActivity(new Intent(ActivityApi.this, ActivityApiCustomMedia.class)); 166 | } 167 | 168 | public void clickPreloading(View view) { 169 | startActivity(new Intent(ActivityApi.this, ActivityPreloading.class)); 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/ActivityApiCustomMedia.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo; 2 | 3 | import android.os.Bundle; 4 | import android.os.Handler; 5 | import android.support.annotation.Nullable; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.view.MenuItem; 8 | import android.view.View; 9 | import android.widget.Toast; 10 | 11 | import com.bumptech.glide.Glide; 12 | 13 | import java.io.IOException; 14 | 15 | import cn.jzvd.JZDataSource; 16 | import cn.jzvd.JZMediaSystem; 17 | import cn.jzvd.Jzvd; 18 | import cn.jzvd.JzvdStd; 19 | import cn.jzvd.demo.CustomMedia.JZMediaExo; 20 | import cn.jzvd.demo.CustomMedia.JZMediaIjk; 21 | import cn.jzvd.demo.CustomMedia.JZMediaSystemAssertFolder; 22 | 23 | /** 24 | * Created by Nathen on 2017/11/23. 25 | */ 26 | 27 | public class ActivityApiCustomMedia extends AppCompatActivity { 28 | JzvdStd jzvdStd; 29 | Handler handler = new Handler();//这里其实并不需要handler,为了防止播放中切换播放器引擎导致的崩溃,实际使用时一般不会遇到,可以随时调用JZVideoPlayer.setMediaInterface(); 30 | 31 | @Override 32 | protected void onCreate(@Nullable Bundle savedInstanceState) { 33 | super.onCreate(savedInstanceState); 34 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 35 | getSupportActionBar().setDisplayShowHomeEnabled(true); 36 | getSupportActionBar().setDisplayShowTitleEnabled(true); 37 | getSupportActionBar().setDisplayUseLogoEnabled(false); 38 | getSupportActionBar().setTitle("CustomMediaPlayer"); 39 | setContentView(R.layout.activity_api_custom_mediaplayer); 40 | 41 | jzvdStd = findViewById(R.id.videoplayer); 42 | 43 | JZDataSource jzDataSource = null; 44 | try { 45 | jzDataSource = new JZDataSource(getAssets().openFd("local_video.mp4")); 46 | jzDataSource.title = "饺子快长大"; 47 | } catch (IOException e) { 48 | e.printStackTrace(); 49 | } 50 | jzvdStd.setUp(jzDataSource, JzvdStd.SCREEN_NORMAL, JZMediaSystemAssertFolder.class); 51 | 52 | 53 | // jzvdStd.setUp("http://jzvd.nathen.cn/342a5f7ef6124a4a8faf00e738b8bee4/cf6d9db0bd4d41f59d09ea0a81e918fd-5287d2089db37e62345123a1be272f8b.mp4" 54 | // , "饺子快长大", JzvdStd.SCREEN_NORMAL, new JZMediaIjk(jzvdStd)); 55 | 56 | Glide.with(this) 57 | .load("http://jzvd-pic.nathen.cn/jzvd-pic/1bb2ebbe-140d-4e2e-abd2-9e7e564f71ac.png") 58 | .into(jzvdStd.thumbImageView); 59 | 60 | } 61 | 62 | 63 | public void clickChangeToIjkplayer(View view) { 64 | Jzvd.releaseAllVideos(); 65 | jzvdStd.setUp("http://jzvd.nathen.cn/342a5f7ef6124a4a8faf00e738b8bee4/cf6d9db0bd4d41f59d09ea0a81e918fd-5287d2089db37e62345123a1be272f8b.mp4" 66 | , "饺子快长大", JzvdStd.SCREEN_NORMAL, JZMediaIjk.class); 67 | jzvdStd.startVideo(); 68 | Toast.makeText(this, "Change to Ijkplayer", Toast.LENGTH_SHORT).show(); 69 | } 70 | 71 | public void clickChangeToSystem(View view) { 72 | Jzvd.releaseAllVideos(); 73 | jzvdStd.setUp("http://jzvd.nathen.cn/342a5f7ef6124a4a8faf00e738b8bee4/cf6d9db0bd4d41f59d09ea0a81e918fd-5287d2089db37e62345123a1be272f8b.mp4" 74 | , "饺子快长大", JzvdStd.SCREEN_NORMAL, JZMediaSystem.class); 75 | jzvdStd.startVideo(); 76 | Toast.makeText(this, "Change to MediaPlayer", Toast.LENGTH_SHORT).show(); 77 | } 78 | 79 | public void clickChangeToExo(View view) { 80 | Jzvd.releaseAllVideos(); 81 | jzvdStd.setUp("http://jzvd.nathen.cn/342a5f7ef6124a4a8faf00e738b8bee4/cf6d9db0bd4d41f59d09ea0a81e918fd-5287d2089db37e62345123a1be272f8b.mp4" 82 | , "饺子快长大", JzvdStd.SCREEN_NORMAL, JZMediaExo.class); 83 | jzvdStd.startVideo(); 84 | Toast.makeText(this, "Change to ExoPlayer", Toast.LENGTH_SHORT).show(); 85 | } 86 | 87 | 88 | @Override 89 | public void onBackPressed() { 90 | if (Jzvd.backPress()) { 91 | return; 92 | } 93 | super.onBackPressed(); 94 | } 95 | 96 | @Override 97 | protected void onPause() { 98 | super.onPause(); 99 | Jzvd.releaseAllVideos(); 100 | } 101 | 102 | @Override 103 | public boolean onOptionsItemSelected(MenuItem item) { 104 | switch (item.getItemId()) { 105 | case android.R.id.home: 106 | finish(); 107 | break; 108 | } 109 | return super.onOptionsItemSelected(item); 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/ActivityApiExtendsNormal.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | 6 | import com.bumptech.glide.Glide; 7 | 8 | import cn.jzvd.Jzvd; 9 | import cn.jzvd.JzvdStd; 10 | 11 | /** 12 | * 适配了普通的Activity,如果不适配并且不继承AppCompatActivity的话会出现Context空指针的情况 13 | * Created by Nathen on 2017/9/19. 14 | */ 15 | public class ActivityApiExtendsNormal extends Activity { 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_extends_normal); 21 | JzvdStd jzvdStd = findViewById(R.id.videoplayer); 22 | jzvdStd.setUp(VideoConstant.videoUrlList[0], "饺子不信" 23 | , JzvdStd.SCREEN_NORMAL); 24 | Glide.with(this) 25 | .load(VideoConstant.videoThumbList[0]) 26 | .into(jzvdStd.thumbImageView); 27 | } 28 | 29 | @Override 30 | public void onBackPressed() { 31 | if (Jzvd.backPress()) { 32 | return; 33 | } 34 | super.onBackPressed(); 35 | } 36 | 37 | @Override 38 | protected void onPause() { 39 | super.onPause(); 40 | Jzvd.releaseAllVideos(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/ActivityApiOrientation.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo; 2 | 3 | import android.content.pm.ActivityInfo; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.view.MenuItem; 8 | 9 | import com.bumptech.glide.Glide; 10 | 11 | import cn.jzvd.Jzvd; 12 | import cn.jzvd.JzvdStd; 13 | 14 | /** 15 | * Created by Nathen on 2016/12/30. 16 | */ 17 | public class ActivityApiOrientation extends AppCompatActivity { 18 | JzvdStd mJzvdStd; 19 | 20 | @Override 21 | protected void onCreate(@Nullable Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 24 | getSupportActionBar().setDisplayShowHomeEnabled(true); 25 | getSupportActionBar().setDisplayShowTitleEnabled(true); 26 | getSupportActionBar().setDisplayUseLogoEnabled(false); 27 | getSupportActionBar().setTitle("Orientation"); 28 | setContentView(R.layout.activity_orientation); 29 | mJzvdStd = findViewById(R.id.jz_video); 30 | mJzvdStd.setUp(VideoConstant.videoUrlList[0], "饺子不信" 31 | , JzvdStd.SCREEN_NORMAL); 32 | Glide.with(this) 33 | .load(VideoConstant.videoThumbList[0]) 34 | .into(mJzvdStd.thumbImageView); 35 | } 36 | 37 | @Override 38 | protected void onResume() { 39 | super.onResume(); 40 | Jzvd.FULLSCREEN_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; 41 | Jzvd.NORMAL_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; 42 | } 43 | 44 | @Override 45 | public void onBackPressed() { 46 | if (Jzvd.backPress()) { 47 | return; 48 | } 49 | super.onBackPressed(); 50 | } 51 | 52 | @Override 53 | protected void onPause() { 54 | super.onPause(); 55 | Jzvd.releaseAllVideos(); 56 | 57 | //Change these two variables back 58 | Jzvd.FULLSCREEN_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE; 59 | Jzvd.NORMAL_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; 60 | } 61 | 62 | @Override 63 | public boolean onOptionsItemSelected(MenuItem item) { 64 | switch (item.getItemId()) { 65 | case android.R.id.home: 66 | finish(); 67 | break; 68 | } 69 | return super.onOptionsItemSelected(item); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/ActivityApiRotationVideoSize.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.MenuItem; 7 | import android.view.View; 8 | 9 | import com.bumptech.glide.Glide; 10 | 11 | import cn.jzvd.Jzvd; 12 | import cn.jzvd.JzvdStd; 13 | 14 | /** 15 | * Created by Nathen on 2017/11/2. 16 | */ 17 | 18 | public class ActivityApiRotationVideoSize extends AppCompatActivity { 19 | 20 | JzvdStd myJzvdStd; 21 | 22 | @Override 23 | protected void onCreate(@Nullable Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 26 | getSupportActionBar().setDisplayShowHomeEnabled(true); 27 | getSupportActionBar().setDisplayShowTitleEnabled(true); 28 | getSupportActionBar().setDisplayUseLogoEnabled(false); 29 | getSupportActionBar().setTitle("RotationAndVideoSize"); 30 | setContentView(R.layout.activity_api_rotation_videosize); 31 | 32 | myJzvdStd = findViewById(R.id.jz_video); 33 | myJzvdStd.setUp(VideoConstant.videoUrls[0][7], VideoConstant.videoTitles[0][7] 34 | , JzvdStd.SCREEN_NORMAL); 35 | Glide.with(this) 36 | .load(VideoConstant.videoThumbs[0][7]) 37 | .into(myJzvdStd.thumbImageView); 38 | // The Point IS 或者这样写也可以 39 | // myJzvdStd.videoRotation = 180; 40 | } 41 | 42 | 43 | @Override 44 | protected void onPause() { 45 | super.onPause(); 46 | Jzvd.releaseAllVideos(); 47 | Jzvd.setVideoImageDisplayType(Jzvd.VIDEO_IMAGE_DISPLAY_TYPE_ADAPTER); 48 | } 49 | 50 | @Override 51 | public void onBackPressed() { 52 | if (Jzvd.backPress()) { 53 | return; 54 | } 55 | super.onBackPressed(); 56 | } 57 | 58 | @Override 59 | public boolean onOptionsItemSelected(MenuItem item) { 60 | switch (item.getItemId()) { 61 | case android.R.id.home: 62 | finish(); 63 | break; 64 | } 65 | return super.onOptionsItemSelected(item); 66 | } 67 | 68 | public void clickRotationTo0(View view) { 69 | Jzvd.setTextureViewRotation(0); 70 | } 71 | 72 | public void clickRotationTo90(View view) { 73 | Jzvd.setTextureViewRotation(90); 74 | } 75 | 76 | public void clickRotationTo180(View view) { 77 | Jzvd.setTextureViewRotation(180); 78 | } 79 | 80 | public void clickRotationTo270(View view) { 81 | Jzvd.setTextureViewRotation(270); 82 | } 83 | 84 | public void clickVideoImageDiaplayAdapter(View view) { 85 | Jzvd.setVideoImageDisplayType(Jzvd.VIDEO_IMAGE_DISPLAY_TYPE_ADAPTER); 86 | } 87 | 88 | public void clickVideoImageDisplayFillParent(View view) { 89 | Jzvd.setVideoImageDisplayType(Jzvd.VIDEO_IMAGE_DISPLAY_TYPE_FILL_PARENT); 90 | } 91 | 92 | public void clickVideoImageDisplayFillCrop(View view) { 93 | Jzvd.setVideoImageDisplayType(Jzvd.VIDEO_IMAGE_DISPLAY_TYPE_FILL_SCROP); 94 | } 95 | 96 | public void clickVideoImageDiaplayOriginal(View view) { 97 | Jzvd.setVideoImageDisplayType(Jzvd.VIDEO_IMAGE_DISPLAY_TYPE_ORIGINAL); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/ActivityApiUIBigChange.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.MenuItem; 7 | 8 | import cn.jzvd.Jzvd; 9 | 10 | /** 11 | * Created by Nathen on 16/7/31. 12 | */ 13 | public class ActivityApiUIBigChange extends AppCompatActivity { 14 | @Override 15 | protected void onCreate(@Nullable Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 18 | getSupportActionBar().setDisplayShowHomeEnabled(true); 19 | getSupportActionBar().setDisplayShowTitleEnabled(true); 20 | getSupportActionBar().setDisplayUseLogoEnabled(false); 21 | getSupportActionBar().setTitle("BigChangeUI"); 22 | setContentView(R.layout.activity_ui_big_change); 23 | 24 | } 25 | 26 | @Override 27 | public void onBackPressed() { 28 | if (Jzvd.backPress()) { 29 | return; 30 | } 31 | super.onBackPressed(); 32 | } 33 | 34 | @Override 35 | protected void onPause() { 36 | super.onPause(); 37 | Jzvd.releaseAllVideos(); 38 | } 39 | 40 | @Override 41 | public boolean onOptionsItemSelected(MenuItem item) { 42 | switch (item.getItemId()) { 43 | case android.R.id.home: 44 | finish(); 45 | break; 46 | } 47 | return super.onOptionsItemSelected(item); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/ActivityApiUISmallChange.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.MenuItem; 7 | 8 | import com.bumptech.glide.Glide; 9 | 10 | import cn.jzvd.Jzvd; 11 | import cn.jzvd.JzvdStd; 12 | import cn.jzvd.demo.CustomJzvd.JzvdStdAutoCompleteAfterFullscreen; 13 | import cn.jzvd.demo.CustomJzvd.JzvdStdMp3; 14 | import cn.jzvd.demo.CustomJzvd.JzvdStdShowShareButtonAfterFullscreen; 15 | import cn.jzvd.demo.CustomJzvd.JzvdStdShowTextureViewAfterAutoComplete; 16 | import cn.jzvd.demo.CustomJzvd.JzvdStdShowTitleAfterFullscreen; 17 | import cn.jzvd.demo.CustomJzvd.JzvdStdSpeed; 18 | import cn.jzvd.demo.CustomJzvd.JzvdStdVolumeAfterFullscreen; 19 | 20 | /** 21 | * Created by Nathen on 16/7/31. 22 | */ 23 | public class ActivityApiUISmallChange extends AppCompatActivity { 24 | JzvdStdShowShareButtonAfterFullscreen jzvdStdWithShareButton; 25 | JzvdStdShowTitleAfterFullscreen jzvdStdShowTitleAfterFullscreen; 26 | JzvdStdShowTextureViewAfterAutoComplete jzvdStdShowTextureViewAfterAutoComplete; 27 | JzvdStdAutoCompleteAfterFullscreen jzvdStdAutoCompleteAfterFullscreen; 28 | JzvdStdVolumeAfterFullscreen jzvdStdVolumeAfterFullscreen; 29 | JzvdStdMp3 jzvdStdMp3; 30 | JzvdStdSpeed jzvdStdSpeed; 31 | 32 | JzvdStd jzvdStd_1_1, jzvdStd_16_9; 33 | 34 | @Override 35 | protected void onCreate(@Nullable Bundle savedInstanceState) { 36 | super.onCreate(savedInstanceState); 37 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 38 | getSupportActionBar().setDisplayShowHomeEnabled(true); 39 | getSupportActionBar().setDisplayShowTitleEnabled(true); 40 | getSupportActionBar().setDisplayUseLogoEnabled(false); 41 | getSupportActionBar().setTitle("SmallChangeUI"); 42 | setContentView(R.layout.activity_ui_small_change); 43 | 44 | jzvdStdWithShareButton = findViewById(R.id.custom_videoplayer_standard_with_share_button); 45 | jzvdStdWithShareButton.setUp(VideoConstant.videoUrlList[3], "饺子想呼吸", Jzvd.SCREEN_NORMAL); 46 | Glide.with(this) 47 | .load(VideoConstant.videoThumbList[3]) 48 | .into(jzvdStdWithShareButton.thumbImageView); 49 | 50 | 51 | jzvdStdShowTitleAfterFullscreen = findViewById(R.id.custom_videoplayer_standard_show_title_after_fullscreen); 52 | jzvdStdShowTitleAfterFullscreen.setUp(VideoConstant.videoUrlList[4], "饺子想摇头", Jzvd.SCREEN_NORMAL); 53 | Glide.with(this) 54 | .load(VideoConstant.videoThumbList[4]) 55 | .into(jzvdStdShowTitleAfterFullscreen.thumbImageView); 56 | 57 | jzvdStdShowTextureViewAfterAutoComplete = findViewById(R.id.custom_videoplayer_standard_show_textureview_aoto_complete); 58 | jzvdStdShowTextureViewAfterAutoComplete.setUp(VideoConstant.videoUrlList[5], "饺子想旅行", Jzvd.SCREEN_NORMAL); 59 | Glide.with(this) 60 | .load(VideoConstant.videoThumbList[5]) 61 | .into(jzvdStdShowTextureViewAfterAutoComplete.thumbImageView); 62 | 63 | jzvdStdAutoCompleteAfterFullscreen = findViewById(R.id.custom_videoplayer_standard_aoto_complete); 64 | jzvdStdAutoCompleteAfterFullscreen.setUp(VideoConstant.videoUrls[0][1], "饺子没来", Jzvd.SCREEN_NORMAL); 65 | Glide.with(this) 66 | .load(VideoConstant.videoThumbs[0][1]) 67 | .into(jzvdStdAutoCompleteAfterFullscreen.thumbImageView); 68 | 69 | jzvdStd_1_1 = findViewById(R.id.jz_videoplayer_1_1); 70 | jzvdStd_1_1.setUp(VideoConstant.videoUrls[0][1], "饺子有事吗", Jzvd.SCREEN_NORMAL); 71 | Glide.with(this) 72 | .load(VideoConstant.videoThumbs[0][1]) 73 | .into(jzvdStd_1_1.thumbImageView); 74 | jzvdStd_1_1.widthRatio = 1; 75 | jzvdStd_1_1.heightRatio = 1; 76 | 77 | jzvdStd_16_9 = findViewById(R.id.jz_videoplayer_16_9); 78 | jzvdStd_16_9.setUp(VideoConstant.videoUrls[0][1], "饺子来不了", Jzvd.SCREEN_NORMAL); 79 | Glide.with(this) 80 | .load(VideoConstant.videoThumbs[0][1]) 81 | .into(jzvdStd_16_9.thumbImageView); 82 | jzvdStd_16_9.widthRatio = 16; 83 | jzvdStd_16_9.heightRatio = 9; 84 | 85 | jzvdStdVolumeAfterFullscreen = findViewById(R.id.jz_videoplayer_volume); 86 | jzvdStdVolumeAfterFullscreen.setUp(VideoConstant.videoUrls[0][1], "饺子摇摆", Jzvd.SCREEN_NORMAL); 87 | Glide.with(this) 88 | .load(VideoConstant.videoThumbs[0][1]) 89 | .into(jzvdStdVolumeAfterFullscreen.thumbImageView); 90 | 91 | jzvdStdMp3 = findViewById(R.id.jz_videoplayer_mp3); 92 | jzvdStdMp3.setUp(VideoConstant.videoUrls[0][1], 93 | "饺子你听", Jzvd.SCREEN_NORMAL); 94 | Glide.with(this) 95 | .load(VideoConstant.videoThumbs[0][1]) 96 | .into(jzvdStdMp3.thumbImageView); 97 | 98 | jzvdStdSpeed = findViewById(R.id.jz_videoplayer_speed); 99 | jzvdStdSpeed.setUp(VideoConstant.videoUrls[0][1], 100 | "饺子快点", Jzvd.SCREEN_NORMAL); 101 | Glide.with(this) 102 | .load(VideoConstant.videoThumbs[0][1]) 103 | .into(jzvdStdSpeed.thumbImageView); 104 | 105 | } 106 | 107 | @Override 108 | public void onBackPressed() { 109 | if (Jzvd.backPress()) { 110 | return; 111 | } 112 | super.onBackPressed(); 113 | } 114 | 115 | @Override 116 | protected void onPause() { 117 | super.onPause(); 118 | Jzvd.releaseAllVideos(); 119 | } 120 | 121 | @Override 122 | public boolean onOptionsItemSelected(MenuItem item) { 123 | switch (item.getItemId()) { 124 | case android.R.id.home: 125 | finish(); 126 | break; 127 | } 128 | return super.onOptionsItemSelected(item); 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/ActivityDirectPlay.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.MenuItem; 7 | import android.view.View; 8 | import android.widget.Toast; 9 | 10 | import cn.jzvd.Jzvd; 11 | import cn.jzvd.JzvdStd; 12 | 13 | /** 14 | * Created by Nathen on 16/7/31. 15 | */ 16 | public class ActivityDirectPlay extends AppCompatActivity { 17 | 18 | @Override 19 | protected void onCreate(@Nullable Bundle savedInstanceState) { 20 | super.onCreate(savedInstanceState); 21 | setContentView(R.layout.activity_listview); 22 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 23 | getSupportActionBar().setDisplayShowHomeEnabled(true); 24 | getSupportActionBar().setDisplayShowTitleEnabled(true); 25 | getSupportActionBar().setDisplayUseLogoEnabled(false); 26 | getSupportActionBar().setTitle("DirectPlay"); 27 | setContentView(R.layout.activity_directly_play); 28 | } 29 | 30 | @Override 31 | public void onBackPressed() { 32 | if (Jzvd.backPress()) { 33 | return; 34 | } 35 | super.onBackPressed(); 36 | } 37 | 38 | @Override 39 | protected void onPause() { 40 | super.onPause(); 41 | Jzvd.releaseAllVideos(); 42 | } 43 | 44 | @Override 45 | public boolean onOptionsItemSelected(MenuItem item) { 46 | switch (item.getItemId()) { 47 | case android.R.id.home: 48 | finish(); 49 | break; 50 | } 51 | return super.onOptionsItemSelected(item); 52 | } 53 | 54 | public void clickFullScreen(View view) { 55 | JzvdStd.startFullscreenDirectly(this, JzvdStd.class, VideoConstant.videoUrlList[6], "饺子辛苦了"); 56 | } 57 | 58 | public void clickTinyWindow(View view) { 59 | Toast.makeText(ActivityDirectPlay.this, "Comming Soon", Toast.LENGTH_SHORT).show(); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/ActivityListView.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.view.MenuItem; 8 | import android.view.View; 9 | 10 | /** 11 | * Created by Nathen on 16/7/31. 12 | */ 13 | public class ActivityListView extends AppCompatActivity { 14 | 15 | @Override 16 | protected void onCreate(@Nullable Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 19 | getSupportActionBar().setDisplayShowHomeEnabled(true); 20 | getSupportActionBar().setDisplayShowTitleEnabled(true); 21 | getSupportActionBar().setDisplayUseLogoEnabled(false); 22 | getSupportActionBar().setTitle("ListView"); 23 | setContentView(R.layout.activity_listview); 24 | } 25 | 26 | @Override 27 | public boolean onOptionsItemSelected(MenuItem item) { 28 | switch (item.getItemId()) { 29 | case android.R.id.home: 30 | finish(); 31 | break; 32 | } 33 | return super.onOptionsItemSelected(item); 34 | } 35 | 36 | public void clickNormal(View view) { 37 | startActivity(new Intent(ActivityListView.this, ActivityListViewNormal.class)); 38 | 39 | } 40 | 41 | public void clickListViewFragmentViewpager(View view) { 42 | startActivity(new Intent(ActivityListView.this, ActivityListViewFragmentViewPager.class)); 43 | 44 | } 45 | 46 | public void clickMultiHolder(View view) { 47 | startActivity(new Intent(ActivityListView.this, ActivityListViewMultiHolder.class)); 48 | 49 | } 50 | 51 | public void clickRecyclerView(View view) { 52 | startActivity(new Intent(ActivityListView.this, ActivityListViewRecyclerView.class)); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/ActivityListViewFragmentViewPager.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.Fragment; 5 | import android.support.v4.app.FragmentManager; 6 | import android.support.v4.app.FragmentPagerAdapter; 7 | import android.support.v4.view.ViewPager; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.view.MenuItem; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | import cn.jzvd.Jzvd; 15 | 16 | /** 17 | * Created by Nathen 18 | * On 2016/02/07 01:01 19 | */ 20 | public class ActivityListViewFragmentViewPager extends AppCompatActivity implements ViewPager.OnPageChangeListener { 21 | List fragmentList = new ArrayList<>(); 22 | 23 | @Override 24 | protected void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | setContentView(R.layout.activity_listview_viewpager); 27 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 28 | getSupportActionBar().setDisplayShowHomeEnabled(true); 29 | getSupportActionBar().setDisplayShowTitleEnabled(true); 30 | getSupportActionBar().setDisplayUseLogoEnabled(false); 31 | getSupportActionBar().setTitle("ActivityListViewFragmentViewPager"); 32 | 33 | fragmentList.add(new FragmentDemo().setIndex(0)); 34 | fragmentList.add(new FragmentDemo().setIndex(1)); 35 | fragmentList.add(new FragmentDemo().setIndex(2)); 36 | 37 | MyAdapter myAdapter = new MyAdapter(getSupportFragmentManager()); 38 | ViewPager viewPager = findViewById(R.id.viewPager); 39 | viewPager.setAdapter(myAdapter); 40 | viewPager.setOnPageChangeListener(this); 41 | } 42 | 43 | @Override 44 | protected void onPause() { 45 | super.onPause(); 46 | Jzvd.releaseAllVideos(); 47 | } 48 | 49 | @Override 50 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 51 | 52 | } 53 | 54 | @Override 55 | public void onPageSelected(int position) { 56 | Jzvd.releaseAllVideos(); 57 | } 58 | 59 | @Override 60 | public void onPageScrollStateChanged(int state) { 61 | 62 | } 63 | 64 | @Override 65 | public void onBackPressed() { 66 | if (Jzvd.backPress()) { 67 | return; 68 | } 69 | super.onBackPressed(); 70 | } 71 | 72 | @Override 73 | public boolean onOptionsItemSelected(MenuItem item) { 74 | switch (item.getItemId()) { 75 | case android.R.id.home: 76 | finish(); 77 | break; 78 | } 79 | return super.onOptionsItemSelected(item); 80 | } 81 | 82 | public class MyAdapter extends FragmentPagerAdapter { 83 | 84 | public MyAdapter(FragmentManager fm) { 85 | super(fm); 86 | } 87 | 88 | @Override 89 | public Fragment getItem(int i) { 90 | return fragmentList.get(i); 91 | } 92 | 93 | @Override 94 | public int getCount() { 95 | return fragmentList.size(); 96 | } 97 | 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/ActivityListViewMultiHolder.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.LayoutInflater; 7 | import android.view.MenuItem; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.AbsListView; 11 | import android.widget.BaseAdapter; 12 | import android.widget.ListView; 13 | import android.widget.TextView; 14 | 15 | import com.bumptech.glide.Glide; 16 | 17 | import cn.jzvd.Jzvd; 18 | import cn.jzvd.JzvdStd; 19 | 20 | /** 21 | * Created by Nathen 22 | * On 2016/05/23 21:34 23 | */ 24 | public class ActivityListViewMultiHolder extends AppCompatActivity { 25 | ListView listView; 26 | VideoListAdapter mAdapter; 27 | 28 | @Override 29 | protected void onCreate(Bundle savedInstanceState) { 30 | super.onCreate(savedInstanceState); 31 | setContentView(R.layout.activity_listview_normal); 32 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 33 | getSupportActionBar().setDisplayShowHomeEnabled(true); 34 | getSupportActionBar().setDisplayShowTitleEnabled(true); 35 | getSupportActionBar().setDisplayUseLogoEnabled(false); 36 | getSupportActionBar().setTitle("MultiHolderListView"); 37 | 38 | 39 | listView = findViewById(R.id.listview); 40 | mAdapter = new VideoListAdapter(this); 41 | listView.setAdapter(mAdapter); 42 | 43 | listView.setOnScrollListener(new AbsListView.OnScrollListener() { 44 | @Override 45 | public void onScrollStateChanged(AbsListView view, int scrollState) { 46 | 47 | } 48 | 49 | @Override 50 | public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { 51 | if (Jzvd.CURRENT_JZVD == null) return; 52 | int lastVisibleItem = firstVisibleItem + visibleItemCount; 53 | int currentPlayPosition = Jzvd.CURRENT_JZVD.positionInList; 54 | // Log.e(TAG, "onScrollReleaseAllVideos: " + 55 | // currentPlayPosition + " " + firstVisibleItem + " " + currentPlayPosition + " " + lastVisibleItem); 56 | if (currentPlayPosition >= 0) { 57 | if ((currentPlayPosition < firstVisibleItem || currentPlayPosition > (lastVisibleItem - 1))) { 58 | if (Jzvd.CURRENT_JZVD.screen != Jzvd.SCREEN_FULLSCREEN) { 59 | Jzvd.releaseAllVideos();//为什么最后一个视频横屏会调用这个,其他地方不会 60 | } 61 | } 62 | } 63 | } 64 | }); 65 | } 66 | 67 | @Override 68 | public void onBackPressed() { 69 | if (Jzvd.backPress()) { 70 | return; 71 | } 72 | super.onBackPressed(); 73 | } 74 | 75 | @Override 76 | protected void onPause() { 77 | super.onPause(); 78 | Jzvd.releaseAllVideos(); 79 | } 80 | 81 | @Override 82 | public boolean onOptionsItemSelected(MenuItem item) { 83 | switch (item.getItemId()) { 84 | case android.R.id.home: 85 | finish(); 86 | break; 87 | } 88 | return super.onOptionsItemSelected(item); 89 | } 90 | 91 | public class VideoListAdapter extends BaseAdapter { 92 | 93 | int[] viewtype = {0, 0, 0, 1, 0, 0, 0, 1, 0, 0};//1 = jzvdStd, 0 = textView 94 | 95 | Context context; 96 | LayoutInflater mInflater; 97 | 98 | public VideoListAdapter(Context context) { 99 | this.context = context; 100 | mInflater = LayoutInflater.from(context); 101 | } 102 | 103 | @Override 104 | public int getCount() { 105 | return viewtype.length; 106 | } 107 | 108 | @Override 109 | public Object getItem(int position) { 110 | return null; 111 | } 112 | 113 | @Override 114 | public long getItemId(int position) { 115 | return position; 116 | } 117 | 118 | @Override 119 | public View getView(int position, View convertView, ViewGroup parent) { 120 | if (getItemViewType(position) == 1) { 121 | VideoHolder viewHolder; 122 | if (convertView != null && convertView.getTag() != null && convertView.getTag() instanceof VideoHolder) { 123 | viewHolder = (VideoHolder) convertView.getTag(); 124 | } else { 125 | viewHolder = new VideoHolder(); 126 | convertView = mInflater.inflate(R.layout.item_videoview, null); 127 | viewHolder.jzvdStd = convertView.findViewById(R.id.videoplayer); 128 | convertView.setTag(viewHolder); 129 | } 130 | 131 | viewHolder.jzvdStd.setUp( 132 | VideoConstant.videoUrls[0][position], 133 | VideoConstant.videoTitles[0][position], Jzvd.SCREEN_NORMAL); 134 | viewHolder.jzvdStd.positionInList = position; 135 | Glide.with(ActivityListViewMultiHolder.this) 136 | .load(VideoConstant.videoThumbs[0][position]) 137 | .into(viewHolder.jzvdStd.thumbImageView); 138 | } else { 139 | TextViewHolder textViewHolder; 140 | if (convertView != null && convertView.getTag() != null && convertView.getTag() instanceof TextViewHolder) { 141 | textViewHolder = (TextViewHolder) convertView.getTag(); 142 | } else { 143 | textViewHolder = new TextViewHolder(); 144 | LayoutInflater mInflater = LayoutInflater.from(context); 145 | convertView = mInflater.inflate(R.layout.item_textview, null); 146 | textViewHolder.textView = convertView.findViewById(R.id.textview); 147 | convertView.setTag(textViewHolder); 148 | } 149 | } 150 | return convertView; 151 | } 152 | 153 | @Override 154 | public int getItemViewType(int position) { 155 | return viewtype[position]; 156 | } 157 | 158 | @Override 159 | public int getViewTypeCount() { 160 | return 2; 161 | } 162 | 163 | class VideoHolder { 164 | JzvdStd jzvdStd; 165 | } 166 | 167 | class TextViewHolder { 168 | TextView textView; 169 | } 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/ActivityListViewNormal.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo; 2 | 3 | import android.hardware.Sensor; 4 | import android.hardware.SensorManager; 5 | import android.os.Bundle; 6 | import android.support.annotation.Nullable; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.view.MenuItem; 9 | import android.widget.AbsListView; 10 | import android.widget.ListView; 11 | 12 | import cn.jzvd.Jzvd; 13 | 14 | /** 15 | * Created by Nathen on 16/7/31. 16 | */ 17 | public class ActivityListViewNormal extends AppCompatActivity { 18 | ListView listView; 19 | 20 | SensorManager sensorManager; 21 | Jzvd.JZAutoFullscreenListener sensorEventListener; 22 | 23 | @Override 24 | protected void onCreate(@Nullable Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 27 | getSupportActionBar().setDisplayShowHomeEnabled(true); 28 | getSupportActionBar().setDisplayShowTitleEnabled(true); 29 | getSupportActionBar().setDisplayUseLogoEnabled(false); 30 | getSupportActionBar().setTitle("NormalListView"); 31 | setContentView(R.layout.activity_listview_normal); 32 | 33 | listView = findViewById(R.id.listview); 34 | listView.setAdapter(new AdapterListView(this, 35 | VideoConstant.videoUrls[0], 36 | VideoConstant.videoTitles[0], 37 | VideoConstant.videoThumbs[0])); 38 | 39 | listView.setOnScrollListener(new AbsListView.OnScrollListener() { 40 | @Override 41 | public void onScrollStateChanged(AbsListView view, int scrollState) { 42 | 43 | } 44 | 45 | @Override 46 | public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { 47 | if (Jzvd.CURRENT_JZVD == null) return; 48 | int lastVisibleItem = firstVisibleItem + visibleItemCount; 49 | int currentPlayPosition = Jzvd.CURRENT_JZVD.positionInList; 50 | // Log.e(TAG, "onScrollReleaseAllVideos: " + 51 | // currentPlayPosition + " " + firstVisibleItem + " " + currentPlayPosition + " " + lastVisibleItem); 52 | if (currentPlayPosition >= 0) { 53 | if ((currentPlayPosition < firstVisibleItem || currentPlayPosition > (lastVisibleItem - 1))) { 54 | if (Jzvd.CURRENT_JZVD.screen != Jzvd.SCREEN_FULLSCREEN) { 55 | Jzvd.releaseAllVideos();//为什么最后一个视频横屏会调用这个,其他地方不会 56 | } 57 | } 58 | } 59 | } 60 | }); 61 | 62 | sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); 63 | sensorEventListener = new Jzvd.JZAutoFullscreenListener(); 64 | } 65 | 66 | @Override 67 | public void onBackPressed() { 68 | if (Jzvd.backPress()) { 69 | return; 70 | } 71 | super.onBackPressed(); 72 | } 73 | 74 | @Override 75 | protected void onResume() { 76 | super.onResume(); 77 | Sensor accelerometerSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); 78 | sensorManager.registerListener(sensorEventListener, accelerometerSensor, SensorManager.SENSOR_DELAY_NORMAL); 79 | } 80 | 81 | @Override 82 | protected void onPause() { 83 | super.onPause(); 84 | sensorManager.unregisterListener(sensorEventListener); 85 | Jzvd.releaseAllVideos(); 86 | } 87 | 88 | @Override 89 | public boolean onOptionsItemSelected(MenuItem item) { 90 | switch (item.getItemId()) { 91 | case android.R.id.home: 92 | finish(); 93 | break; 94 | } 95 | return super.onOptionsItemSelected(item); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/ActivityListViewRecyclerView.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.view.MenuItem; 9 | import android.view.View; 10 | 11 | import cn.jzvd.Jzvd; 12 | 13 | /** 14 | * Created by yujunkui on 16/8/29. 15 | */ 16 | public class ActivityListViewRecyclerView extends AppCompatActivity { 17 | RecyclerView recyclerView; 18 | AdapterRecyclerView adapterVideoList; 19 | 20 | @Override 21 | protected void onCreate(@Nullable Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 24 | getSupportActionBar().setDisplayShowHomeEnabled(true); 25 | getSupportActionBar().setDisplayShowTitleEnabled(true); 26 | getSupportActionBar().setDisplayUseLogoEnabled(false); 27 | getSupportActionBar().setTitle("RecyclerView"); 28 | setContentView(R.layout.activity_recyclerview_content); 29 | 30 | recyclerView = findViewById(R.id.recyclerview); 31 | recyclerView.setLayoutManager(new LinearLayoutManager(this)); 32 | 33 | adapterVideoList = new AdapterRecyclerView(this); 34 | recyclerView.setAdapter(adapterVideoList); 35 | recyclerView.addOnChildAttachStateChangeListener(new RecyclerView.OnChildAttachStateChangeListener() { 36 | @Override 37 | public void onChildViewAttachedToWindow(View view) { 38 | 39 | } 40 | 41 | @Override 42 | public void onChildViewDetachedFromWindow(View view) { 43 | Jzvd jzvd = view.findViewById(R.id.videoplayer); 44 | if (jzvd != null && Jzvd.CURRENT_JZVD != null && 45 | jzvd.jzDataSource.containsTheUrl(Jzvd.CURRENT_JZVD.jzDataSource.getCurrentUrl())) { 46 | if (Jzvd.CURRENT_JZVD != null && Jzvd.CURRENT_JZVD.screen != Jzvd.SCREEN_FULLSCREEN) { 47 | Jzvd.releaseAllVideos(); 48 | } 49 | } 50 | } 51 | }); 52 | } 53 | 54 | @Override 55 | public void onBackPressed() { 56 | if (Jzvd.backPress()) { 57 | return; 58 | } 59 | super.onBackPressed(); 60 | } 61 | 62 | @Override 63 | protected void onPause() { 64 | super.onPause(); 65 | Jzvd.releaseAllVideos(); 66 | } 67 | 68 | @Override 69 | public boolean onOptionsItemSelected(MenuItem item) { 70 | switch (item.getItemId()) { 71 | case android.R.id.home: 72 | finish(); 73 | break; 74 | } 75 | return super.onOptionsItemSelected(item); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/ActivityMain.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.view.View; 8 | 9 | import com.bumptech.glide.Glide; 10 | 11 | import cn.jzvd.Jzvd; 12 | import cn.jzvd.demo.CustomJzvd.MyJzvdStd; 13 | 14 | /** 15 | * Created by Nathen on 16/7/22. 16 | */ 17 | public class ActivityMain extends AppCompatActivity { 18 | 19 | MyJzvdStd myJzvdStd; 20 | 21 | @Override 22 | protected void onCreate(@Nullable Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | setContentView(R.layout.activity_main); 25 | 26 | myJzvdStd = findViewById(R.id.jz_video); 27 | myJzvdStd.setUp("http://jzvd.nathen.cn/342a5f7ef6124a4a8faf00e738b8bee4/cf6d9db0bd4d41f59d09ea0a81e918fd-5287d2089db37e62345123a1be272f8b.mp4" 28 | , "饺子快长大"); 29 | Glide.with(this).load("http://jzvd-pic.nathen.cn/jzvd-pic/1bb2ebbe-140d-4e2e-abd2-9e7e564f71ac.png").into(myJzvdStd.thumbImageView); 30 | 31 | } 32 | 33 | @Override 34 | protected void onPause() { 35 | super.onPause(); 36 | Jzvd.releaseAllVideos(); 37 | } 38 | 39 | @Override 40 | public void onBackPressed() { 41 | if (Jzvd.backPress()) { 42 | return; 43 | } 44 | super.onBackPressed(); 45 | } 46 | 47 | public void clickApi(View view) { 48 | startActivity(new Intent(ActivityMain.this, ActivityApi.class)); 49 | } 50 | 51 | public void clickListView(View view) { 52 | startActivity(new Intent(ActivityMain.this, ActivityListView.class)); 53 | } 54 | 55 | public void clickTinyWindow(View view) { 56 | startActivity(new Intent(ActivityMain.this, ActivityTinyWindow.class)); 57 | } 58 | 59 | public void clickDirectPlay(View view) { 60 | startActivity(new Intent(ActivityMain.this, ActivityDirectPlay.class)); 61 | } 62 | 63 | public void clickWebView(View view) { 64 | startActivity(new Intent(ActivityMain.this, ActivityWebView.class)); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/ActivityPreloading.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.View; 7 | 8 | import com.bumptech.glide.Glide; 9 | 10 | import cn.jzvd.Jzvd; 11 | import cn.jzvd.JzvdStd; 12 | import cn.jzvd.demo.CustomMedia.JZMediaIjk; 13 | 14 | public class ActivityPreloading extends AppCompatActivity { 15 | 16 | JzvdStd jzvdStd; 17 | 18 | @Override 19 | protected void onCreate(@Nullable Bundle savedInstanceState) { 20 | super.onCreate(savedInstanceState); 21 | setContentView(R.layout.activity_preloading); 22 | jzvdStd = findViewById(R.id.jz_video); 23 | 24 | // jzvdStd.setUp("http://jzvd.nathen.cn/342a5f7ef6124a4a8faf00e738b8bee4/cf6d9db0bd4d41f59d09ea0a81e918fd-5287d2089db37e62345123a1be272f8b.mp4" 25 | // , "饺子快长大", Jzvd.SCREEN_NORMAL, JZMediaIjk.class); 26 | jzvdStd.setUp("http://jzvd.nathen.cn/4f965ad507ef4194a60a943a34cfe147/32af151ea132471f92c9ced2cff785ea-5287d2089db37e62345123a1be272f8b.mp4" 27 | , "饺子快长大", Jzvd.SCREEN_NORMAL, JZMediaIjk.class); 28 | 29 | 30 | // jzvdStd.setUp("http://jzvd.nathen.cn/342a5f7ef6124a4a8faf00e738b8bee4/cf6d9db0bd4d41f59d09ea0a81e918fd-5287d2089db37e62345123a1be272f8b.mp4" 31 | // , "饺子快长大"); 32 | // jzvdStd.setUp("http://jzvd.nathen.cn/4f965ad507ef4194a60a943a34cfe147/32af151ea132471f92c9ced2cff785ea-5287d2089db37e62345123a1be272f8b.mp4" 33 | // , "饺子快长大"); 34 | Glide.with(this).load("http://jzvd-pic.nathen.cn/jzvd-pic/1bb2ebbe-140d-4e2e-abd2-9e7e564f71ac.png").into(jzvdStd.thumbImageView); 35 | 36 | } 37 | 38 | public void clickStartPreloading(View view) { 39 | jzvdStd.startPreloading(); 40 | } 41 | 42 | public void clickStartVideoAfterPreloading(View view) { 43 | jzvdStd.startVideoAfterPreloading(); 44 | } 45 | 46 | @Override 47 | protected void onPause() { 48 | super.onPause(); 49 | Jzvd.releaseAllVideos(); 50 | } 51 | 52 | @Override 53 | public void onBackPressed() { 54 | if (Jzvd.backPress()) { 55 | return; 56 | } 57 | super.onBackPressed(); 58 | } 59 | 60 | 61 | } 62 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/ActivityPreloadingList.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | 7 | import cn.jzvd.Jzvd; 8 | 9 | public class ActivityPreloadingList extends AppCompatActivity { 10 | 11 | 12 | @Override 13 | protected void onCreate(@Nullable Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 16 | getSupportActionBar().setDisplayShowHomeEnabled(true); 17 | getSupportActionBar().setDisplayShowTitleEnabled(true); 18 | getSupportActionBar().setDisplayUseLogoEnabled(false); 19 | getSupportActionBar().setTitle("Preloading"); 20 | setContentView(R.layout.activity_api); 21 | 22 | } 23 | 24 | @Override 25 | protected void onPause() { 26 | super.onPause(); 27 | Jzvd.releaseAllVideos(); 28 | } 29 | 30 | @Override 31 | public void onBackPressed() { 32 | if (Jzvd.backPress()) { 33 | return; 34 | } 35 | super.onBackPressed(); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/ActivityTinyWindow.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.MenuItem; 7 | import android.view.View; 8 | import android.widget.Toast; 9 | 10 | import com.bumptech.glide.Glide; 11 | 12 | import cn.jzvd.Jzvd; 13 | import cn.jzvd.JzvdStd; 14 | import cn.jzvd.demo.CustomJzvd.JzvdStdTinyWindow; 15 | 16 | /** 17 | * Created by Nathen on 2017/10/31. 18 | */ 19 | 20 | public class ActivityTinyWindow extends AppCompatActivity { 21 | 22 | JzvdStdTinyWindow jzvdStdTinyWindow; 23 | 24 | @Override 25 | protected void onCreate(@Nullable Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 28 | getSupportActionBar().setDisplayShowHomeEnabled(true); 29 | getSupportActionBar().setDisplayShowTitleEnabled(true); 30 | getSupportActionBar().setDisplayUseLogoEnabled(false); 31 | getSupportActionBar().setTitle("TinyWindow"); 32 | setContentView(R.layout.activity_tiny_window); 33 | 34 | jzvdStdTinyWindow = findViewById(R.id.jz_video); 35 | jzvdStdTinyWindow.setUp("http://jzvd.nathen.cn/342a5f7ef6124a4a8faf00e738b8bee4/cf6d9db0bd4d41f59d09ea0a81e918fd-5287d2089db37e62345123a1be272f8b.mp4", "饺子快长大" 36 | , JzvdStd.SCREEN_NORMAL); 37 | Glide.with(this) 38 | .load("http://jzvd-pic.nathen.cn/jzvd-pic/1bb2ebbe-140d-4e2e-abd2-9e7e564f71ac.png") 39 | .into(jzvdStdTinyWindow.thumbImageView); 40 | 41 | } 42 | 43 | 44 | @Override 45 | protected void onPause() { 46 | super.onPause(); 47 | Jzvd.releaseAllVideos(); 48 | } 49 | 50 | @Override 51 | public void onBackPressed() { 52 | if (Jzvd.backPress()) { 53 | return; 54 | } 55 | super.onBackPressed(); 56 | } 57 | 58 | @Override 59 | public boolean onOptionsItemSelected(MenuItem item) { 60 | switch (item.getItemId()) { 61 | case android.R.id.home: 62 | finish(); 63 | break; 64 | } 65 | return super.onOptionsItemSelected(item); 66 | } 67 | 68 | 69 | public void clickTinyWindow(View view) { 70 | jzvdStdTinyWindow.gotoScreenTiny(); 71 | } 72 | 73 | public void clickAutoTinyListViewRecyclerView(View view) { 74 | Toast.makeText(this, "comming soon", Toast.LENGTH_SHORT).show(); 75 | // startActivity(new Intent(this, ActivityTinyWindowRecycleView.class)); 76 | } 77 | 78 | public void clickAutoTinyListViewRecyclerViewMultiHolder(View view) { 79 | Toast.makeText(this, "comming soon", Toast.LENGTH_SHORT).show(); 80 | // startActivity(new Intent(this, ActivityTinyWindowRecycleViewMultiHolder.class)); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/ActivityTinyWindowRecycleView.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.view.MenuItem; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.FrameLayout; 12 | 13 | import cn.jzvd.Jzvd; 14 | import cn.jzvd.demo.CustomJzvd.JzvdStdTinyWindow; 15 | 16 | /** 17 | * Created by Nathen on 2017/11/1. 18 | */ 19 | 20 | public class ActivityTinyWindowRecycleView extends AppCompatActivity { 21 | RecyclerView recyclerView; 22 | AdapterRecyclerViewTiny adapterVideoList; 23 | 24 | @Override 25 | protected void onCreate(@Nullable Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 28 | getSupportActionBar().setDisplayShowHomeEnabled(true); 29 | getSupportActionBar().setDisplayShowTitleEnabled(true); 30 | getSupportActionBar().setDisplayUseLogoEnabled(false); 31 | getSupportActionBar().setTitle("RecyclerViewTinyWindow"); 32 | setContentView(R.layout.activity_recyclerview_content); 33 | 34 | recyclerView = findViewById(R.id.recyclerview); 35 | recyclerView.setLayoutManager(new LinearLayoutManager(this)); 36 | 37 | adapterVideoList = new AdapterRecyclerViewTiny(this); 38 | recyclerView.setAdapter(adapterVideoList); 39 | recyclerView.addOnChildAttachStateChangeListener(new RecyclerView.OnChildAttachStateChangeListener() { 40 | @Override 41 | public void onChildViewAttachedToWindow(View view) {//这个的本质是gotoThisJzvd,不管他是不是原来的容器 42 | //如果这个容器中jzvd的url是currentJzvd的url,那么直接回到这里,不用管其他的 43 | JzvdStdTinyWindow jzvd = view.findViewById(R.id.videoplayer); 44 | JzvdStdTinyWindow currentJzvd = (JzvdStdTinyWindow) Jzvd.CURRENT_JZVD; 45 | if (jzvd != null && currentJzvd != null && 46 | jzvd.jzDataSource.containsTheUrl(Jzvd.CURRENT_JZVD.jzDataSource.getCurrentUrl()) 47 | && Jzvd.CURRENT_JZVD.state == Jzvd.STATE_PLAYING) { 48 | ViewGroup vp = (ViewGroup) jzvd.getParent(); 49 | vp.removeAllViews(); 50 | ((ViewGroup) currentJzvd.getParent()).removeView(currentJzvd); 51 | FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); 52 | vp.addView(currentJzvd, lp); 53 | currentJzvd.setScreenNormal(); 54 | Jzvd.CONTAINER_LIST.pop(); 55 | } 56 | } 57 | 58 | @Override 59 | public void onChildViewDetachedFromWindow(View view) { 60 | JzvdStdTinyWindow jzvd = view.findViewById(R.id.videoplayer); 61 | if (jzvd != null && Jzvd.CURRENT_JZVD != null && 62 | jzvd.jzDataSource.containsTheUrl(Jzvd.CURRENT_JZVD.jzDataSource.getCurrentUrl()) 63 | && Jzvd.CURRENT_JZVD.screen != Jzvd.SCREEN_TINY) { 64 | if (Jzvd.CURRENT_JZVD.state == Jzvd.STATE_PAUSE) { 65 | Jzvd.releaseAllVideos(); 66 | } else { 67 | ((JzvdStdTinyWindow) Jzvd.CURRENT_JZVD).gotoScreenTiny(); 68 | } 69 | } 70 | } 71 | }); 72 | 73 | } 74 | 75 | @Override 76 | public void onBackPressed() { 77 | if (Jzvd.backPress()) { 78 | return; 79 | } 80 | super.onBackPressed(); 81 | } 82 | 83 | @Override 84 | protected void onPause() { 85 | super.onPause(); 86 | Jzvd.releaseAllVideos(); 87 | } 88 | 89 | @Override 90 | public boolean onOptionsItemSelected(MenuItem item) { 91 | switch (item.getItemId()) { 92 | case android.R.id.home: 93 | finish(); 94 | break; 95 | } 96 | return super.onOptionsItemSelected(item); 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/ActivityTinyWindowRecycleViewMultiHolder.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.view.LayoutInflater; 9 | import android.view.MenuItem; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.FrameLayout; 13 | import android.widget.TextView; 14 | 15 | import com.bumptech.glide.Glide; 16 | 17 | import cn.jzvd.Jzvd; 18 | import cn.jzvd.JzvdStd; 19 | import cn.jzvd.demo.CustomJzvd.JzvdStdTinyWindow; 20 | 21 | /** 22 | * Created by Nathen on 2017/11/1. 23 | */ 24 | 25 | public class ActivityTinyWindowRecycleViewMultiHolder extends AppCompatActivity { 26 | 27 | RecyclerView recyclerView; 28 | AdapterRecyclerView videoAdapter; 29 | 30 | @Override 31 | protected void onCreate(@Nullable Bundle savedInstanceState) { 32 | super.onCreate(savedInstanceState); 33 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 34 | getSupportActionBar().setDisplayShowHomeEnabled(true); 35 | getSupportActionBar().setDisplayShowTitleEnabled(true); 36 | getSupportActionBar().setDisplayUseLogoEnabled(false); 37 | getSupportActionBar().setTitle("RecycleViewMultiHolderTinyWindow"); 38 | setContentView(R.layout.activity_recyclerview_content); 39 | 40 | recyclerView = findViewById(R.id.recyclerview); 41 | recyclerView.setLayoutManager(new LinearLayoutManager(this)); 42 | 43 | videoAdapter = new AdapterRecyclerView(); 44 | recyclerView.setAdapter(videoAdapter); 45 | recyclerView.addOnChildAttachStateChangeListener(new RecyclerView.OnChildAttachStateChangeListener() { 46 | @Override 47 | public void onChildViewAttachedToWindow(View view) { 48 | JzvdStdTinyWindow jzvd = view.findViewById(R.id.videoplayer); 49 | JzvdStdTinyWindow currentJzvd = (JzvdStdTinyWindow) Jzvd.CURRENT_JZVD; 50 | if (jzvd != null && currentJzvd != null && 51 | jzvd.jzDataSource.containsTheUrl(Jzvd.CURRENT_JZVD.jzDataSource.getCurrentUrl()) 52 | && Jzvd.CURRENT_JZVD.state == Jzvd.STATE_PLAYING) { 53 | ViewGroup vp = (ViewGroup) jzvd.getParent(); 54 | vp.removeAllViews(); 55 | ((ViewGroup) currentJzvd.getParent()).removeView(currentJzvd); 56 | FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); 57 | vp.addView(currentJzvd, lp); 58 | currentJzvd.setScreenNormal(); 59 | Jzvd.CONTAINER_LIST.pop(); 60 | } 61 | } 62 | 63 | @Override 64 | public void onChildViewDetachedFromWindow(View view) { 65 | JzvdStdTinyWindow jzvd = view.findViewById(R.id.videoplayer); 66 | if (jzvd != null && Jzvd.CURRENT_JZVD != null && 67 | jzvd.jzDataSource.containsTheUrl(Jzvd.CURRENT_JZVD.jzDataSource.getCurrentUrl()) 68 | && Jzvd.CURRENT_JZVD.screen != Jzvd.SCREEN_TINY) { 69 | if (Jzvd.CURRENT_JZVD.state == Jzvd.STATE_PAUSE) { 70 | Jzvd.releaseAllVideos(); 71 | } else { 72 | ((JzvdStdTinyWindow) Jzvd.CURRENT_JZVD).gotoScreenTiny(); 73 | } 74 | } 75 | } 76 | }); 77 | 78 | } 79 | 80 | @Override 81 | protected void onPause() { 82 | super.onPause(); 83 | Jzvd.releaseAllVideos(); 84 | } 85 | 86 | @Override 87 | public void onBackPressed() { 88 | if (Jzvd.backPress()) { 89 | return; 90 | } 91 | super.onBackPressed(); 92 | } 93 | 94 | @Override 95 | public boolean onOptionsItemSelected(MenuItem item) { 96 | switch (item.getItemId()) { 97 | case android.R.id.home: 98 | finish(); 99 | break; 100 | } 101 | return super.onOptionsItemSelected(item); 102 | } 103 | 104 | public class AdapterRecyclerView extends RecyclerView.Adapter { 105 | 106 | @Override 107 | public int getItemViewType(int position) { 108 | if (position != 4 && position != 7) { 109 | return 0;//非视频 110 | } 111 | return 1;//视频 112 | } 113 | 114 | @Override 115 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 116 | View view; 117 | if (viewType == 1) { 118 | view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_videoview, parent, false); 119 | return new VideoHolder(view); 120 | } else { 121 | view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_textview, parent, false); 122 | return new TextHolder(view); 123 | } 124 | } 125 | 126 | @Override 127 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 128 | if (position != 4 && position != 7) { 129 | TextHolder textHolder = (TextHolder) holder; 130 | } else { 131 | VideoHolder videoHolder = (VideoHolder) holder; 132 | videoHolder.jzvdStd.setUp( 133 | VideoConstant.videoUrls[0][position], 134 | VideoConstant.videoTitles[0][position], Jzvd.SCREEN_NORMAL); 135 | videoHolder.jzvdStd.positionInList = position; 136 | Glide.with(ActivityTinyWindowRecycleViewMultiHolder.this).load(VideoConstant.videoThumbs[0][position]).into(videoHolder.jzvdStd.thumbImageView); 137 | } 138 | } 139 | 140 | @Override 141 | public int getItemCount() { 142 | return 10; 143 | } 144 | 145 | class VideoHolder extends RecyclerView.ViewHolder { 146 | JzvdStd jzvdStd; 147 | 148 | public VideoHolder(View itemView) { 149 | super(itemView); 150 | jzvdStd = itemView.findViewById(R.id.videoplayer); 151 | } 152 | } 153 | 154 | class TextHolder extends RecyclerView.ViewHolder { 155 | TextView textView; 156 | 157 | public TextHolder(View itemView) { 158 | super(itemView); 159 | textView = itemView.findViewById(R.id.textview); 160 | } 161 | } 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/ActivityWebView.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.MenuItem; 7 | import android.view.ViewGroup; 8 | import android.webkit.JavascriptInterface; 9 | import android.webkit.WebView; 10 | import android.widget.AbsoluteLayout; 11 | import android.widget.LinearLayout; 12 | 13 | import com.bumptech.glide.Glide; 14 | 15 | import cn.jzvd.JZUtils; 16 | import cn.jzvd.Jzvd; 17 | import cn.jzvd.JzvdStd; 18 | 19 | /** 20 | * Created by Nathen on 16/10/13. 21 | */ 22 | 23 | public class ActivityWebView extends AppCompatActivity { 24 | WebView mWebView; 25 | 26 | @Override 27 | protected void onCreate(@Nullable Bundle savedInstanceState) { 28 | super.onCreate(savedInstanceState); 29 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 30 | getSupportActionBar().setDisplayShowHomeEnabled(true); 31 | getSupportActionBar().setDisplayShowTitleEnabled(true); 32 | getSupportActionBar().setDisplayUseLogoEnabled(false); 33 | getSupportActionBar().setTitle("WebView"); 34 | getWindow().setBackgroundDrawable(null); 35 | setContentView(R.layout.activity_webview); 36 | mWebView = findViewById(R.id.webview); 37 | mWebView.getSettings().setJavaScriptEnabled(true); 38 | mWebView.addJavascriptInterface(new JZCallBack(), "jzvd"); 39 | mWebView.loadUrl("file:///android_asset/jzvd.html"); 40 | } 41 | 42 | @Override 43 | public void onBackPressed() { 44 | if (Jzvd.backPress()) { 45 | return; 46 | } 47 | super.onBackPressed(); 48 | } 49 | 50 | @Override 51 | protected void onPause() { 52 | super.onPause(); 53 | Jzvd.releaseAllVideos(); 54 | } 55 | 56 | @Override 57 | public boolean onOptionsItemSelected(MenuItem item) { 58 | switch (item.getItemId()) { 59 | case android.R.id.home: 60 | finish(); 61 | break; 62 | } 63 | return super.onOptionsItemSelected(item); 64 | } 65 | 66 | public class JZCallBack { 67 | 68 | @JavascriptInterface 69 | public void adViewJiaoZiVideoPlayer(final int width, final int height, final int top, final int left, final int index) { 70 | runOnUiThread(() -> { 71 | if (index == 0) { 72 | JzvdStd jzvdStd = new JzvdStd(ActivityWebView.this); 73 | jzvdStd.setUp(VideoConstant.videoUrlList[1], "饺子骑大马", 74 | Jzvd.SCREEN_NORMAL); 75 | Glide.with(ActivityWebView.this) 76 | .load(VideoConstant.videoThumbList[1]) 77 | .into(jzvdStd.thumbImageView); 78 | ViewGroup.LayoutParams ll = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); 79 | AbsoluteLayout.LayoutParams layoutParams = new AbsoluteLayout.LayoutParams(ll); 80 | layoutParams.y = JZUtils.dip2px(ActivityWebView.this, top); 81 | layoutParams.x = JZUtils.dip2px(ActivityWebView.this, left); 82 | layoutParams.height = JZUtils.dip2px(ActivityWebView.this, height); 83 | layoutParams.width = JZUtils.dip2px(ActivityWebView.this, width); 84 | 85 | LinearLayout linearLayout = new LinearLayout(ActivityWebView.this); 86 | linearLayout.addView(jzvdStd); 87 | mWebView.addView(linearLayout, layoutParams); 88 | } else { 89 | JzvdStd jzvdStd = new JzvdStd(ActivityWebView.this); 90 | jzvdStd.setUp(VideoConstant.videoUrlList[2], "饺子失态了", 91 | Jzvd.SCREEN_NORMAL); 92 | Glide.with(ActivityWebView.this) 93 | .load(VideoConstant.videoThumbList[2]) 94 | .into(jzvdStd.thumbImageView); 95 | ViewGroup.LayoutParams ll = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); 96 | AbsoluteLayout.LayoutParams layoutParams = new AbsoluteLayout.LayoutParams(ll); 97 | layoutParams.y = JZUtils.dip2px(ActivityWebView.this, top); 98 | layoutParams.x = JZUtils.dip2px(ActivityWebView.this, left); 99 | layoutParams.height = JZUtils.dip2px(ActivityWebView.this, height); 100 | layoutParams.width = JZUtils.dip2px(ActivityWebView.this, width); 101 | 102 | LinearLayout linearLayout = new LinearLayout(ActivityWebView.this); 103 | linearLayout.addView(jzvdStd); 104 | mWebView.addView(linearLayout, layoutParams); 105 | } 106 | 107 | }); 108 | 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/AdapterListView.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.BaseAdapter; 8 | 9 | import com.bumptech.glide.Glide; 10 | 11 | import cn.jzvd.Jzvd; 12 | import cn.jzvd.JzvdStd; 13 | 14 | /** 15 | * Created by Nathen 16 | * On 2016/02/07 01:20 17 | */ 18 | public class AdapterListView extends BaseAdapter { 19 | 20 | public static final String TAG = "JZVD"; 21 | 22 | Context context; 23 | 24 | String[] videoUrls; 25 | String[] videoTitles; 26 | String[] videoThumbs; 27 | 28 | public AdapterListView(Context context, String[] videoUrls, String[] videoTitles, String[] videoThumbs) { 29 | this.context = context; 30 | this.videoUrls = videoUrls; 31 | this.videoTitles = videoTitles; 32 | this.videoThumbs = videoThumbs; 33 | } 34 | 35 | @Override 36 | public int getCount() { 37 | return videoUrls.length; 38 | } 39 | 40 | @Override 41 | public Object getItem(int position) { 42 | return null; 43 | } 44 | 45 | @Override 46 | public long getItemId(int position) { 47 | return position; 48 | } 49 | 50 | @Override 51 | public View getView(int position, View convertView, ViewGroup parent) { 52 | 53 | ViewHolder viewHolder; 54 | if (null == convertView) { 55 | viewHolder = new ViewHolder(); 56 | LayoutInflater mInflater = LayoutInflater.from(context); 57 | convertView = mInflater.inflate(R.layout.item_videoview, null); 58 | convertView.setTag(viewHolder); 59 | } else { 60 | viewHolder = (ViewHolder) convertView.getTag(); 61 | } 62 | viewHolder.jzvdStd = convertView.findViewById(R.id.videoplayer); 63 | viewHolder.jzvdStd.setUp( 64 | videoUrls[position], 65 | videoTitles[position], Jzvd.SCREEN_NORMAL); 66 | Glide.with(convertView.getContext()) 67 | .load(videoThumbs[position]) 68 | .into(viewHolder.jzvdStd.thumbImageView); 69 | viewHolder.jzvdStd.positionInList = position; 70 | return convertView; 71 | } 72 | 73 | class ViewHolder { 74 | JzvdStd jzvdStd; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/AdapterRecyclerView.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.util.Log; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | import com.bumptech.glide.Glide; 12 | 13 | import cn.jzvd.Jzvd; 14 | import cn.jzvd.JzvdStd; 15 | 16 | public class AdapterRecyclerView extends RecyclerView.Adapter { 17 | 18 | public static final String TAG = "AdapterRecyclerView"; 19 | int[] videoIndexs = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; 20 | private Context context; 21 | 22 | public AdapterRecyclerView(Context context) { 23 | this.context = context; 24 | } 25 | 26 | @Override 27 | public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 28 | MyViewHolder holder = new MyViewHolder(LayoutInflater.from( 29 | context).inflate(R.layout.item_videoview, parent, 30 | false)); 31 | return holder; 32 | } 33 | 34 | @SuppressLint("LongLogTag") 35 | @Override 36 | public void onBindViewHolder(MyViewHolder holder, int position) { 37 | Log.i(TAG, "onBindViewHolder [" + holder.jzvdStd.hashCode() + "] position=" + position); 38 | 39 | holder.jzvdStd.setUp( 40 | VideoConstant.videoUrls[0][position], 41 | VideoConstant.videoTitles[0][position], Jzvd.SCREEN_NORMAL); 42 | Glide.with(holder.jzvdStd.getContext()).load(VideoConstant.videoThumbs[0][position]).into(holder.jzvdStd.thumbImageView); 43 | } 44 | 45 | @Override 46 | public int getItemCount() { 47 | return videoIndexs.length; 48 | } 49 | 50 | class MyViewHolder extends RecyclerView.ViewHolder { 51 | JzvdStd jzvdStd; 52 | 53 | public MyViewHolder(View itemView) { 54 | super(itemView); 55 | jzvdStd = itemView.findViewById(R.id.videoplayer); 56 | } 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/AdapterRecyclerViewTiny.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.util.Log; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | import com.bumptech.glide.Glide; 12 | 13 | import cn.jzvd.Jzvd; 14 | import cn.jzvd.demo.CustomJzvd.JzvdStdTinyWindow; 15 | 16 | public class AdapterRecyclerViewTiny extends RecyclerView.Adapter { 17 | 18 | public static final String TAG = "AdapterRecyclerView"; 19 | int[] videoIndexs = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; 20 | private Context context; 21 | 22 | public AdapterRecyclerViewTiny(Context context) { 23 | this.context = context; 24 | } 25 | 26 | @Override 27 | public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 28 | MyViewHolder holder = new MyViewHolder(LayoutInflater.from( 29 | context).inflate(R.layout.item_videoview_tiny, parent, 30 | false)); 31 | return holder; 32 | } 33 | 34 | @SuppressLint("LongLogTag") 35 | @Override 36 | public void onBindViewHolder(MyViewHolder holder, int position) { 37 | Log.i(TAG, "onBindViewHolder [" + holder.jzvdStd.hashCode() + "] position=" + position); 38 | if (holder.jzvdStd.getTag() != null) 39 | holder.jzvdStd = ((View) holder.jzvdStd.getTag()).findViewById(R.id.videoplayer); 40 | holder.jzvdStd.setUp( 41 | VideoConstant.videoUrls[0][position], 42 | VideoConstant.videoTitles[0][position], Jzvd.SCREEN_NORMAL); 43 | Glide.with(holder.jzvdStd.getContext()).load(VideoConstant.videoThumbs[0][position]).into(holder.jzvdStd.thumbImageView); 44 | } 45 | 46 | @Override 47 | public int getItemCount() { 48 | return videoIndexs.length; 49 | } 50 | 51 | class MyViewHolder extends RecyclerView.ViewHolder { 52 | JzvdStdTinyWindow jzvdStd; 53 | 54 | public MyViewHolder(View itemView) { 55 | super(itemView); 56 | jzvdStd = itemView.findViewById(R.id.videoplayer); 57 | jzvdStd.setTag(itemView); 58 | } 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/ApplicationDemo.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | 6 | import com.danikula.videocache.HttpProxyCacheServer; 7 | 8 | /** 9 | * Created by Nathen 10 | * On 2015/12/01 11:29 11 | */ 12 | public class ApplicationDemo extends Application { 13 | 14 | private HttpProxyCacheServer proxy; 15 | 16 | public static HttpProxyCacheServer getProxy(Context context) { 17 | ApplicationDemo app = (ApplicationDemo) context.getApplicationContext(); 18 | return app.proxy == null ? (app.proxy = app.newProxy()) : app.proxy; 19 | } 20 | 21 | @Override 22 | public void onCreate() { 23 | super.onCreate(); 24 | // LeakCanary.install(this); 25 | 26 | } 27 | 28 | private HttpProxyCacheServer newProxy() { 29 | return new HttpProxyCacheServer(this); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/CustomJzvd/JzvdStdAutoCompleteAfterFullscreen.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo.CustomJzvd; 2 | 3 | import android.content.Context; 4 | import android.media.AudioManager; 5 | import android.util.AttributeSet; 6 | import android.util.Log; 7 | import android.view.WindowManager; 8 | 9 | import cn.jzvd.JZMediaInterface; 10 | import cn.jzvd.JZUtils; 11 | import cn.jzvd.JzvdStd; 12 | 13 | /** 14 | * 全屏状态播放完成,不退出全屏 15 | * Created by Nathen on 2016/11/26. 16 | */ 17 | public class JzvdStdAutoCompleteAfterFullscreen extends JzvdStd { 18 | public JzvdStdAutoCompleteAfterFullscreen(Context context) { 19 | super(context); 20 | } 21 | 22 | public JzvdStdAutoCompleteAfterFullscreen(Context context, AttributeSet attrs) { 23 | super(context, attrs); 24 | } 25 | 26 | @Override 27 | public void startVideo() { 28 | if (screen == SCREEN_FULLSCREEN) { 29 | Log.d(TAG, "startVideo [" + this.hashCode() + "] "); 30 | JZMediaInterface.SAVED_SURFACE = null; 31 | addTextureView(); 32 | AudioManager mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE); 33 | mAudioManager.requestAudioFocus(onAudioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT); 34 | JZUtils.scanForActivity(getContext()).getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 35 | // JZMediaPlayer.instance().positionInList = positionInList; 36 | onStatePreparing(); 37 | } else { 38 | super.startVideo(); 39 | } 40 | } 41 | 42 | @Override 43 | public void onAutoCompletion() { 44 | if (screen == SCREEN_FULLSCREEN) { 45 | onStateAutoComplete(); 46 | } else { 47 | super.onAutoCompletion(); 48 | } 49 | 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/CustomJzvd/JzvdStdList.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo.CustomJzvd; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | 6 | import cn.jzvd.JZDataSource; 7 | import cn.jzvd.JZUtils; 8 | import cn.jzvd.Jzvd; 9 | import cn.jzvd.JzvdStd; 10 | 11 | public class JzvdStdList extends JzvdStd { 12 | public JzvdStdList(Context context) { 13 | super(context); 14 | } 15 | 16 | public JzvdStdList(Context context, AttributeSet attrs) { 17 | super(context, attrs); 18 | } 19 | 20 | @Override 21 | public void setUp(JZDataSource jzDataSource, int screen, Class mediaInterface) { 22 | super.setUp(jzDataSource, screen, mediaInterface); 23 | 24 | if (jzDataSource.containsTheUrl(Jzvd.CURRENT_JZVD.jzDataSource.getCurrentUrl())) { 25 | long position = 0; 26 | try { 27 | position = Jzvd.CURRENT_JZVD.mediaInterface.getCurrentPosition(); 28 | } catch (IllegalStateException e) { 29 | e.printStackTrace(); 30 | } 31 | if (position != 0) { 32 | JZUtils.saveProgress(getContext(), Jzvd.CURRENT_JZVD.jzDataSource.getCurrentUrl(), position); 33 | } 34 | Jzvd.releaseAllVideos(); 35 | } 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/CustomJzvd/JzvdStdMp3.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo.CustomJzvd; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.View; 6 | 7 | import cn.jzvd.JzvdStd; 8 | import cn.jzvd.demo.R; 9 | 10 | /** 11 | * 这个本质上就是播放的时候不隐藏缩略图 12 | */ 13 | public class JzvdStdMp3 extends JzvdStd { 14 | 15 | public JzvdStdMp3(Context context) { 16 | super(context); 17 | } 18 | 19 | public JzvdStdMp3(Context context, AttributeSet attrs) { 20 | super(context, attrs); 21 | } 22 | 23 | @Override 24 | public int getLayoutId() { 25 | return R.layout.jz_layout_standard_mp3; 26 | } 27 | 28 | @Override 29 | public void onClick(View v) { 30 | if (v.getId() == cn.jzvd.R.id.thumb && 31 | (state == STATE_PLAYING || 32 | state == STATE_PAUSE)) { 33 | onClickUiToggle(); 34 | } else if (v.getId() == R.id.fullscreen) { 35 | 36 | } else { 37 | super.onClick(v); 38 | } 39 | } 40 | 41 | //changeUiTo 真能能修改ui的方法 42 | @Override 43 | public void changeUiToNormal() { 44 | super.changeUiToNormal(); 45 | } 46 | 47 | @Override 48 | public void changeUiToPreparing() { 49 | super.changeUiToPreparing(); 50 | } 51 | 52 | @Override 53 | public void changeUiToPlayingShow() { 54 | super.changeUiToPlayingShow(); 55 | thumbImageView.setVisibility(View.VISIBLE); 56 | 57 | } 58 | 59 | @Override 60 | public void changeUiToPlayingClear() { 61 | super.changeUiToPlayingClear(); 62 | thumbImageView.setVisibility(View.VISIBLE); 63 | } 64 | 65 | @Override 66 | public void changeUiToPauseShow() { 67 | super.changeUiToPauseShow(); 68 | thumbImageView.setVisibility(View.VISIBLE); 69 | } 70 | 71 | @Override 72 | public void changeUiToPauseClear() { 73 | super.changeUiToPauseClear(); 74 | thumbImageView.setVisibility(View.VISIBLE); 75 | } 76 | 77 | @Override 78 | public void changeUiToComplete() { 79 | super.changeUiToComplete(); 80 | } 81 | 82 | @Override 83 | public void changeUiToError() { 84 | super.changeUiToError(); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/CustomJzvd/JzvdStdShowShareButtonAfterFullscreen.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo.CustomJzvd; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.View; 6 | import android.widget.ImageView; 7 | import android.widget.Toast; 8 | 9 | import cn.jzvd.JzvdStd; 10 | import cn.jzvd.demo.R; 11 | 12 | /** 13 | * Created by Nathen 14 | * On 2016/04/22 00:54 15 | */ 16 | public class JzvdStdShowShareButtonAfterFullscreen extends JzvdStd { 17 | 18 | public ImageView shareButton; 19 | 20 | public JzvdStdShowShareButtonAfterFullscreen(Context context) { 21 | super(context); 22 | } 23 | 24 | public JzvdStdShowShareButtonAfterFullscreen(Context context, AttributeSet attrs) { 25 | super(context, attrs); 26 | } 27 | 28 | @Override 29 | public void init(Context context) { 30 | super.init(context); 31 | shareButton = findViewById(R.id.share); 32 | shareButton.setOnClickListener(this); 33 | 34 | } 35 | 36 | @Override 37 | public int getLayoutId() { 38 | return R.layout.layout_std_with_share_button; 39 | } 40 | 41 | @Override 42 | public void onClick(View v) { 43 | super.onClick(v); 44 | if (v.getId() == R.id.share) { 45 | Toast.makeText(getContext(), "Whatever the icon means", Toast.LENGTH_SHORT).show(); 46 | } 47 | } 48 | 49 | @Override 50 | public void setScreenNormal() { 51 | super.setScreenNormal(); 52 | shareButton.setVisibility(View.INVISIBLE); 53 | } 54 | 55 | @Override 56 | public void setScreenFullscreen() { 57 | super.setScreenFullscreen(); 58 | shareButton.setVisibility(View.VISIBLE); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/CustomJzvd/JzvdStdShowTextureViewAfterAutoComplete.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo.CustomJzvd; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.View; 6 | 7 | import cn.jzvd.JzvdStd; 8 | 9 | /** 10 | * ////TODO 这个还有重要的逻辑问题,reset的时候是否设置普通屏幕的方向,普通屏幕的方向应该在什么地方设置 11 | * Created by Nathen on 2016/11/6. 12 | */ 13 | public class JzvdStdShowTextureViewAfterAutoComplete extends JzvdStd { 14 | public JzvdStdShowTextureViewAfterAutoComplete(Context context) { 15 | super(context); 16 | } 17 | 18 | public JzvdStdShowTextureViewAfterAutoComplete(Context context, AttributeSet attrs) { 19 | super(context, attrs); 20 | } 21 | 22 | @Override 23 | public void onAutoCompletion() { 24 | super.onAutoCompletion(); 25 | thumbImageView.setVisibility(View.GONE); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/CustomJzvd/JzvdStdShowTitleAfterFullscreen.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo.CustomJzvd; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.View; 6 | 7 | import cn.jzvd.JZDataSource; 8 | import cn.jzvd.JzvdStd; 9 | 10 | /** 11 | * Created by Nathen 12 | * On 2016/04/27 10:49 13 | */ 14 | public class JzvdStdShowTitleAfterFullscreen extends JzvdStd { 15 | public JzvdStdShowTitleAfterFullscreen(Context context) { 16 | super(context); 17 | } 18 | 19 | public JzvdStdShowTitleAfterFullscreen(Context context, AttributeSet attrs) { 20 | super(context, attrs); 21 | } 22 | 23 | @Override 24 | public void setUp(JZDataSource jzDataSource, int screen) { 25 | super.setUp(jzDataSource, screen); 26 | if (this.screen == SCREEN_FULLSCREEN) { 27 | titleTextView.setVisibility(View.VISIBLE); 28 | } else { 29 | titleTextView.setVisibility(View.INVISIBLE); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/CustomJzvd/JzvdStdSpeed.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo.CustomJzvd; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.View; 6 | import android.widget.TextView; 7 | 8 | import cn.jzvd.JzvdStd; 9 | import cn.jzvd.demo.R; 10 | 11 | public class JzvdStdSpeed extends JzvdStd { 12 | TextView tvSpeed; 13 | int currentSpeedIndex = 2; 14 | 15 | public JzvdStdSpeed(Context context) { 16 | super(context); 17 | } 18 | 19 | public JzvdStdSpeed(Context context, AttributeSet attrs) { 20 | super(context, attrs); 21 | } 22 | 23 | @Override 24 | public void init(Context context) { 25 | super.init(context); 26 | tvSpeed = findViewById(R.id.tv_speed); 27 | tvSpeed.setOnClickListener(this); 28 | } 29 | 30 | public void setScreenNormal() { 31 | super.setScreenNormal(); 32 | tvSpeed.setVisibility(View.GONE); 33 | } 34 | 35 | @Override 36 | public void setScreenFullscreen() { 37 | super.setScreenFullscreen(); 38 | if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) 39 | tvSpeed.setVisibility(View.VISIBLE); 40 | 41 | if (jzDataSource.objects == null) { 42 | Object[] object = {2}; 43 | jzDataSource.objects = object; 44 | currentSpeedIndex = 2; 45 | } else { 46 | currentSpeedIndex = (int) jzDataSource.objects[0]; 47 | } 48 | if (currentSpeedIndex == 2) { 49 | tvSpeed.setText("倍速"); 50 | } else { 51 | tvSpeed.setText(getSpeedFromIndex(currentSpeedIndex) + "X"); 52 | } 53 | } 54 | 55 | 56 | @Override 57 | public void onClick(View v) { 58 | super.onClick(v); 59 | if (v.getId() == R.id.tv_speed) {//0.5 0.75 1.0 1.25 1.5 1.75 2.0 60 | if (currentSpeedIndex == 6) { 61 | currentSpeedIndex = 0; 62 | } else { 63 | currentSpeedIndex += 1; 64 | } 65 | mediaInterface.setSpeed(getSpeedFromIndex(currentSpeedIndex)); 66 | tvSpeed.setText(getSpeedFromIndex(currentSpeedIndex) + "X"); 67 | jzDataSource.objects[0] = currentSpeedIndex; 68 | } 69 | } 70 | 71 | @Override 72 | public int getLayoutId() { 73 | return R.layout.layout_std_speed; 74 | } 75 | 76 | private float getSpeedFromIndex(int index) { 77 | float ret = 0f; 78 | if (index == 0) { 79 | ret = 0.5f; 80 | } else if (index == 1) { 81 | ret = 0.75f; 82 | } else if (index == 2) { 83 | ret = 1.0f; 84 | } else if (index == 3) { 85 | ret = 1.25f; 86 | } else if (index == 4) { 87 | ret = 1.5f; 88 | } else if (index == 5) { 89 | ret = 1.75f; 90 | } else if (index == 6) { 91 | ret = 2.0f; 92 | } 93 | return ret; 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/CustomJzvd/JzvdStdTinyWindow.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo.CustomJzvd; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.util.Log; 6 | import android.view.Gravity; 7 | import android.view.ViewGroup; 8 | import android.widget.FrameLayout; 9 | 10 | import cn.jzvd.JZDataSource; 11 | import cn.jzvd.JZUtils; 12 | import cn.jzvd.JzvdStd; 13 | 14 | /** 15 | * 这个类里详细定义了进入小窗的方式,进入小窗之后小窗的操作等 16 | */ 17 | public class JzvdStdTinyWindow extends JzvdStd { 18 | public JzvdStdTinyWindow(Context context) { 19 | super(context); 20 | } 21 | 22 | public JzvdStdTinyWindow(Context context, AttributeSet attrs) { 23 | super(context, attrs); 24 | } 25 | 26 | @Override 27 | public void setUp(JZDataSource jzDataSource, int screen, Class mediaInterface) { 28 | super.setUp(jzDataSource, screen, mediaInterface); 29 | } 30 | 31 | public void gotoScreenTiny() { 32 | Log.i(TAG, "startWindowTiny " + " [" + this.hashCode() + "] "); 33 | if (state == STATE_NORMAL || state == STATE_ERROR || state == STATE_AUTO_COMPLETE) 34 | return; 35 | ViewGroup vg = (ViewGroup) getParent(); 36 | vg.removeView(this); 37 | cloneAJzvd(vg); 38 | CONTAINER_LIST.add(vg); 39 | ViewGroup vgg = (ViewGroup) (JZUtils.scanForActivity(getContext())).getWindow().getDecorView();//和他也没有关系 40 | FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(400, 400); 41 | lp.gravity = Gravity.RIGHT | Gravity.BOTTOM; 42 | //添加滑动事件等 43 | vgg.addView(this, lp); 44 | setScreenTiny(); 45 | } 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/CustomJzvd/JzvdStdVolumeAfterFullscreen.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo.CustomJzvd; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | 6 | import cn.jzvd.JzvdStd; 7 | 8 | /** 9 | * Created by pc on 2018/1/17. 10 | */ 11 | 12 | public class JzvdStdVolumeAfterFullscreen extends JzvdStd { 13 | public JzvdStdVolumeAfterFullscreen(Context context) { 14 | super(context); 15 | } 16 | 17 | public JzvdStdVolumeAfterFullscreen(Context context, AttributeSet attrs) { 18 | super(context, attrs); 19 | } 20 | 21 | @Override 22 | public void onPrepared() { 23 | super.onPrepared(); 24 | if (screen == SCREEN_FULLSCREEN) { 25 | mediaInterface.setVolume(1f, 1f); 26 | } else { 27 | mediaInterface.setVolume(0f, 0f); 28 | } 29 | } 30 | 31 | /** 32 | * 进入全屏模式的时候关闭静音模式 33 | */ 34 | @Override 35 | public void gotoScreenFullscreen() { 36 | super.gotoScreenFullscreen(); 37 | } 38 | 39 | @Override 40 | public void setScreenFullscreen() { 41 | super.setScreenFullscreen(); 42 | if (mediaInterface != null) 43 | mediaInterface.setVolume(1f, 1f); 44 | } 45 | 46 | @Override 47 | public void setScreenNormal() { 48 | super.setScreenNormal(); 49 | if (mediaInterface != null) 50 | mediaInterface.setVolume(0f, 0f); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/CustomJzvd/MyJzvdStd.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo.CustomJzvd; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.util.Log; 6 | import android.view.MotionEvent; 7 | import android.view.View; 8 | import android.widget.SeekBar; 9 | 10 | import cn.jzvd.JzvdStd; 11 | import cn.jzvd.demo.R; 12 | 13 | /** 14 | * 这里可以监听到视频播放的生命周期和播放状态 15 | * 所有关于视频的逻辑都应该写在这里 16 | * Created by Nathen on 2017/7/2. 17 | */ 18 | public class MyJzvdStd extends JzvdStd { 19 | public MyJzvdStd(Context context) { 20 | super(context); 21 | } 22 | 23 | public MyJzvdStd(Context context, AttributeSet attrs) { 24 | super(context, attrs); 25 | } 26 | 27 | @Override 28 | public void init(Context context) { 29 | super.init(context); 30 | } 31 | 32 | @Override 33 | public void onClick(View v) { 34 | super.onClick(v); 35 | int i = v.getId(); 36 | if (i == cn.jzvd.R.id.fullscreen) { 37 | Log.i(TAG, "onClick: fullscreen button"); 38 | } else if (i == R.id.start) { 39 | Log.i(TAG, "onClick: start button"); 40 | } 41 | } 42 | 43 | @Override 44 | public boolean onTouch(View v, MotionEvent event) { 45 | super.onTouch(v, event); 46 | int id = v.getId(); 47 | if (id == cn.jzvd.R.id.surface_container) { 48 | switch (event.getAction()) { 49 | case MotionEvent.ACTION_UP: 50 | if (mChangePosition) { 51 | Log.i(TAG, "Touch screen seek position"); 52 | } 53 | if (mChangeVolume) { 54 | Log.i(TAG, "Touch screen change volume"); 55 | } 56 | break; 57 | } 58 | } 59 | 60 | return false; 61 | } 62 | 63 | @Override 64 | public int getLayoutId() { 65 | return R.layout.jz_layout_std; 66 | } 67 | 68 | @Override 69 | public void startVideo() { 70 | super.startVideo(); 71 | Log.i(TAG, "startVideo"); 72 | } 73 | 74 | @Override 75 | public void onStopTrackingTouch(SeekBar seekBar) { 76 | super.onStopTrackingTouch(seekBar); 77 | Log.i(TAG, "Seek position "); 78 | } 79 | 80 | @Override 81 | public void gotoScreenFullscreen() { 82 | super.gotoScreenFullscreen(); 83 | Log.i(TAG, "goto Fullscreen"); 84 | } 85 | 86 | @Override 87 | public void gotoScreenNormal() { 88 | super.gotoScreenNormal(); 89 | Log.i(TAG, "quit Fullscreen"); 90 | } 91 | 92 | @Override 93 | public void autoFullscreen(float x) { 94 | super.autoFullscreen(x); 95 | Log.i(TAG, "auto Fullscreen"); 96 | } 97 | 98 | @Override 99 | public void onClickUiToggle() { 100 | super.onClickUiToggle(); 101 | Log.i(TAG, "click blank"); 102 | } 103 | 104 | //onState 代表了播放器引擎的回调,播放视频各个过程的状态的回调 105 | @Override 106 | public void onStateNormal() { 107 | super.onStateNormal(); 108 | } 109 | 110 | @Override 111 | public void onStatePreparing() { 112 | super.onStatePreparing(); 113 | } 114 | 115 | @Override 116 | public void onStatePlaying() { 117 | super.onStatePlaying(); 118 | } 119 | 120 | @Override 121 | public void onStatePause() { 122 | super.onStatePause(); 123 | } 124 | 125 | @Override 126 | public void onStateError() { 127 | super.onStateError(); 128 | } 129 | 130 | @Override 131 | public void onStateAutoComplete() { 132 | super.onStateAutoComplete(); 133 | Log.i(TAG, "Auto complete"); 134 | } 135 | 136 | //changeUiTo 真能能修改ui的方法 137 | @Override 138 | public void changeUiToNormal() { 139 | super.changeUiToNormal(); 140 | } 141 | 142 | @Override 143 | public void changeUiToPreparing() { 144 | super.changeUiToPreparing(); 145 | } 146 | 147 | @Override 148 | public void changeUiToPlayingShow() { 149 | super.changeUiToPlayingShow(); 150 | } 151 | 152 | @Override 153 | public void changeUiToPlayingClear() { 154 | super.changeUiToPlayingClear(); 155 | } 156 | 157 | @Override 158 | public void changeUiToPauseShow() { 159 | super.changeUiToPauseShow(); 160 | } 161 | 162 | @Override 163 | public void changeUiToPauseClear() { 164 | super.changeUiToPauseClear(); 165 | } 166 | 167 | @Override 168 | public void changeUiToComplete() { 169 | super.changeUiToComplete(); 170 | } 171 | 172 | @Override 173 | public void changeUiToError() { 174 | super.changeUiToError(); 175 | } 176 | 177 | @Override 178 | public void onInfo(int what, int extra) { 179 | super.onInfo(what, extra); 180 | } 181 | 182 | @Override 183 | public void onError(int what, int extra) { 184 | super.onError(what, extra); 185 | } 186 | 187 | } 188 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/CustomMedia/JZMediaIjk.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo.CustomMedia; 2 | 3 | import android.graphics.SurfaceTexture; 4 | import android.media.AudioManager; 5 | import android.media.MediaPlayer; 6 | import android.os.Handler; 7 | import android.os.HandlerThread; 8 | import android.view.Surface; 9 | 10 | import java.io.IOException; 11 | 12 | import cn.jzvd.JZMediaInterface; 13 | import cn.jzvd.Jzvd; 14 | import tv.danmaku.ijk.media.player.IMediaPlayer; 15 | import tv.danmaku.ijk.media.player.IjkMediaPlayer; 16 | import tv.danmaku.ijk.media.player.IjkTimedText; 17 | 18 | /** 19 | * 20 | * Created by Nathen on 2017/11/18. 21 | */ 22 | 23 | public class JZMediaIjk extends JZMediaInterface implements IMediaPlayer.OnPreparedListener, IMediaPlayer.OnVideoSizeChangedListener, IMediaPlayer.OnCompletionListener, IMediaPlayer.OnErrorListener, IMediaPlayer.OnInfoListener, IMediaPlayer.OnBufferingUpdateListener, IMediaPlayer.OnSeekCompleteListener, IMediaPlayer.OnTimedTextListener { 24 | IjkMediaPlayer ijkMediaPlayer; 25 | 26 | public JZMediaIjk(Jzvd jzvd) { 27 | super(jzvd); 28 | } 29 | 30 | @Override 31 | public void start() { 32 | if (ijkMediaPlayer != null) ijkMediaPlayer.start(); 33 | } 34 | 35 | @Override 36 | public void prepare() { 37 | 38 | release(); 39 | mMediaHandlerThread = new HandlerThread("JZVD"); 40 | mMediaHandlerThread.start(); 41 | mMediaHandler = new Handler(mMediaHandlerThread.getLooper());//主线程还是非主线程,就在这里 42 | handler = new Handler(); 43 | 44 | mMediaHandler.post(() -> { 45 | 46 | ijkMediaPlayer = new IjkMediaPlayer(); 47 | ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec", 0); 48 | ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "opensles", 0); 49 | ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "overlay-format", IjkMediaPlayer.SDL_FCC_RV32); 50 | ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "framedrop", 1); 51 | ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "start-on-prepared", 0); 52 | ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "http-detect-range-support", 0); 53 | ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_CODEC, "skip_loop_filter", 48); 54 | ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "max-buffer-size", 1024 * 1024); 55 | ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "enable-accurate-seek", 1); 56 | 57 | ijkMediaPlayer.setOnPreparedListener(JZMediaIjk.this); 58 | ijkMediaPlayer.setOnVideoSizeChangedListener(JZMediaIjk.this); 59 | ijkMediaPlayer.setOnCompletionListener(JZMediaIjk.this); 60 | ijkMediaPlayer.setOnErrorListener(JZMediaIjk.this); 61 | ijkMediaPlayer.setOnInfoListener(JZMediaIjk.this); 62 | ijkMediaPlayer.setOnBufferingUpdateListener(JZMediaIjk.this); 63 | ijkMediaPlayer.setOnSeekCompleteListener(JZMediaIjk.this); 64 | ijkMediaPlayer.setOnTimedTextListener(JZMediaIjk.this); 65 | 66 | try { 67 | ijkMediaPlayer.setDataSource(jzvd.jzDataSource.getCurrentUrl().toString()); 68 | ijkMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 69 | ijkMediaPlayer.setScreenOnWhilePlaying(true); 70 | ijkMediaPlayer.prepareAsync(); 71 | 72 | ijkMediaPlayer.setSurface(new Surface(jzvd.textureView.getSurfaceTexture())); 73 | } catch (IOException e) { 74 | e.printStackTrace(); 75 | } 76 | }); 77 | 78 | } 79 | 80 | @Override 81 | public void pause() { 82 | ijkMediaPlayer.pause(); 83 | } 84 | 85 | @Override 86 | public boolean isPlaying() { 87 | return ijkMediaPlayer.isPlaying(); 88 | } 89 | 90 | @Override 91 | public void seekTo(long time) { 92 | ijkMediaPlayer.seekTo(time); 93 | } 94 | 95 | @Override 96 | public void release() { 97 | if (mMediaHandler != null && mMediaHandlerThread != null && ijkMediaPlayer != null) {//不知道有没有妖孽 98 | HandlerThread tmpHandlerThread = mMediaHandlerThread; 99 | IjkMediaPlayer tmpMediaPlayer = ijkMediaPlayer; 100 | JZMediaInterface.SAVED_SURFACE = null; 101 | 102 | mMediaHandler.post(() -> { 103 | tmpMediaPlayer.setSurface(null); 104 | tmpMediaPlayer.release(); 105 | tmpHandlerThread.quit(); 106 | }); 107 | ijkMediaPlayer = null; 108 | } 109 | } 110 | 111 | @Override 112 | public long getCurrentPosition() { 113 | return ijkMediaPlayer.getCurrentPosition(); 114 | } 115 | 116 | @Override 117 | public long getDuration() { 118 | return ijkMediaPlayer.getDuration(); 119 | } 120 | 121 | @Override 122 | public void setVolume(float leftVolume, float rightVolume) { 123 | ijkMediaPlayer.setVolume(leftVolume, rightVolume); 124 | } 125 | 126 | @Override 127 | public void setSpeed(float speed) { 128 | ijkMediaPlayer.setSpeed(speed); 129 | } 130 | 131 | @Override 132 | public void onPrepared(IMediaPlayer iMediaPlayer) { 133 | handler.post(() -> jzvd.onPrepared()); 134 | } 135 | 136 | @Override 137 | public void onVideoSizeChanged(IMediaPlayer iMediaPlayer, int i, int i1, int i2, int i3) { 138 | handler.post(() -> jzvd.onVideoSizeChanged(iMediaPlayer.getVideoWidth(), iMediaPlayer.getVideoHeight())); 139 | } 140 | 141 | @Override 142 | public boolean onError(IMediaPlayer iMediaPlayer, final int what, final int extra) { 143 | handler.post(() -> jzvd.onError(what, extra)); 144 | return true; 145 | } 146 | 147 | @Override 148 | public boolean onInfo(IMediaPlayer iMediaPlayer, final int what, final int extra) { 149 | handler.post(() -> jzvd.onInfo(what, extra)); 150 | return false; 151 | } 152 | 153 | @Override 154 | public void onBufferingUpdate(IMediaPlayer iMediaPlayer, final int percent) { 155 | handler.post(() -> jzvd.setBufferProgress(percent)); 156 | } 157 | 158 | @Override 159 | public void onSeekComplete(IMediaPlayer iMediaPlayer) { 160 | handler.post(() -> jzvd.onSeekComplete()); 161 | } 162 | 163 | @Override 164 | public void onTimedText(IMediaPlayer iMediaPlayer, IjkTimedText ijkTimedText) { 165 | 166 | } 167 | 168 | @Override 169 | public void setSurface(Surface surface) { 170 | ijkMediaPlayer.setSurface(surface); 171 | } 172 | 173 | @Override 174 | public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { 175 | if (SAVED_SURFACE == null) { 176 | SAVED_SURFACE = surface; 177 | prepare(); 178 | } else { 179 | jzvd.textureView.setSurfaceTexture(SAVED_SURFACE); 180 | } 181 | } 182 | 183 | @Override 184 | public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { 185 | 186 | } 187 | 188 | @Override 189 | public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { 190 | return false; 191 | } 192 | 193 | @Override 194 | public void onSurfaceTextureUpdated(SurfaceTexture surface) { 195 | 196 | } 197 | 198 | @Override 199 | public void onCompletion(IMediaPlayer iMediaPlayer) { 200 | handler.post(() -> jzvd.onAutoCompletion()); 201 | } 202 | } 203 | -------------------------------------------------------------------------------- /app/src/main/java/cn/jzvd/demo/FragmentDemo.java: -------------------------------------------------------------------------------- 1 | package cn.jzvd.demo; 2 | 3 | 4 | import android.os.Bundle; 5 | import android.support.v4.app.Fragment; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.AbsListView; 10 | import android.widget.ListView; 11 | 12 | import cn.jzvd.Jzvd; 13 | 14 | /** 15 | * Created by Nathen on 2017/6/9. 16 | */ 17 | public class FragmentDemo extends Fragment { 18 | 19 | ListView listView; 20 | int index; 21 | 22 | public FragmentDemo setIndex(int index) { 23 | this.index = index; 24 | return this; 25 | } 26 | 27 | @Override 28 | public void onCreate(Bundle savedInstanceState) { 29 | super.onCreate(savedInstanceState); 30 | } 31 | 32 | @Override 33 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 34 | Bundle savedInastanceState) { 35 | listView = (ListView) inflater.inflate(R.layout.layout_list, container, false); 36 | listView.setAdapter(new AdapterListView(getActivity(), 37 | VideoConstant.videoUrls[index], 38 | VideoConstant.videoTitles[index], 39 | VideoConstant.videoThumbs[index])); 40 | listView.setOnScrollListener(new AbsListView.OnScrollListener() { 41 | @Override 42 | public void onScrollStateChanged(AbsListView view, int scrollState) { 43 | 44 | } 45 | 46 | @Override 47 | public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { 48 | // Jzvd.onScrollReleaseAllVideos(view, firstVisibleItem, visibleItemCount, totalItemCount); 49 | 50 | if (Jzvd.CURRENT_JZVD == null) return; 51 | int lastVisibleItem = firstVisibleItem + visibleItemCount; 52 | int currentPlayPosition = Jzvd.CURRENT_JZVD.positionInList; 53 | // Log.e(TAG, "onScrollReleaseAllVideos: " + 54 | // currentPlayPosition + " " + firstVisibleItem + " " + currentPlayPosition + " " + lastVisibleItem); 55 | if (currentPlayPosition >= 0) { 56 | if ((currentPlayPosition < firstVisibleItem || currentPlayPosition > (lastVisibleItem - 1))) { 57 | if (Jzvd.CURRENT_JZVD.screen != Jzvd.SCREEN_FULLSCREEN) { 58 | Jzvd.releaseAllVideos();//为什么最后一个视频横屏会调用这个,其他地方不会 59 | } 60 | } 61 | } 62 | } 63 | }); 64 | return listView; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/share_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/skin_enlarge_video.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lipangit/JiaoZiVideoPlayer/3db479b1a816965336fa5884708037a0a2971c33/app/src/main/res/drawable/skin_enlarge_video.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/skin_seek_progress.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/skin_shrink_video.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lipangit/JiaoZiVideoPlayer/3db479b1a816965336fa5884708037a0a2971c33/app/src/main/res/drawable/skin_shrink_video.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_api.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | 16 | 17 | 20 | 21 | 25 | 26 | 27 |