├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── jackchan │ │ └── videoplayer │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── jackchan │ │ │ └── videoplayer │ │ │ ├── MainActivity.java │ │ │ ├── adapter │ │ │ └── VideoPlayListAdatper.java │ │ │ ├── bean │ │ │ └── VideoPlayerItemInfo.java │ │ │ ├── utils │ │ │ └── MediaHelper.java │ │ │ └── view │ │ │ ├── RecycleViewDivider.java │ │ │ ├── VideoMediaController.java │ │ │ └── VideoPlayer.java │ └── res │ │ ├── anim │ │ ├── bottom_enter.xml │ │ └── bottom_exit.xml │ │ ├── drawable-hdpi │ │ ├── biz_video_progress_thumb.png │ │ ├── comment_video_normal.png │ │ ├── enlarge_fullscreen.png │ │ ├── more_pgc_comment_normal_night.png │ │ ├── new_pause_video.png │ │ ├── new_play_video.png │ │ ├── qq_allshare_normal.png │ │ ├── replay_video.png │ │ └── share_video.png │ │ ├── drawable │ │ ├── sb_bg.xml │ │ ├── sb_progress.xml │ │ ├── sb_progress_drawable.xml │ │ ├── sb_second.xml │ │ └── tv_time_bg.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── item_video_play.xml │ │ ├── video_controller.xml │ │ └── video_play.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── beautiful.jpg │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── color.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── jackchan │ └── videoplayer │ └── ExampleUnitTest.java ├── art ├── VideoMediaController1.jpg ├── VideoMediaController2.jpg └── VideoPlayer.jpg ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | 14 | 26 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 1.7 61 | 62 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## TextureView+MediaPlayer实现在线短视频播放 2 | 3 | 4 | 5 | ## 列表item布局文件 6 | 7 | ```xml 8 | 9 | 13 | 14 | 17 | 18 | 19 | 26 | 27 | 28 | 33 | 34 | 35 | 36 | 37 | 43 | 44 | 49 | 50 | 57 | 58 | 66 | 67 | 73 | 74 | 81 | 82 | 87 | 88 | 89 | 90 | ``` 91 | 92 | 其中VideoPlayer是自定义View,继承于RelativeLayout,是视频播放的关键类 93 | 94 | ## VideoPlayer 95 | 96 | ```java 97 | public VideoPlayer(Context context, AttributeSet attrs, int defStyleAttr) { 98 | super(context, attrs, defStyleAttr); 99 | initView(); 100 | } 101 | //初始化布局 102 | private void initView() { 103 | View view = View.inflate(getContext(), R.layout.video_play, this); 104 | ButterKnife.bind(this,view); 105 | ... 106 | } 107 | ``` 108 | 109 | ```xml 110 | 111 | 115 | 116 | 117 | 122 | 123 | 124 | 128 | 129 | 130 | ``` 131 | 132 | 实现视频播放功能的是TextureView,VideoMediaController视频播放控制器,自定义View,继承于RelativeLayout 133 | 134 | ### 视频播放(视频的初始化) 135 | 136 | ```java 137 | private void play(String url){ 138 | try { 139 | mPlayer = MediaHelper.getInstance(); 140 | mPlayer.reset(); 141 | mPlayer.setDataSource(url); 142 | //让MediaPlayer和TextureView进行视频画面的结合 143 | mPlayer.setSurface(mSurface); 144 | //设置监听 145 | mPlayer.setOnBufferingUpdateListener(onBufferingUpdateListener); 146 | mPlayer.setOnCompletionListener(onCompletionListener); 147 | mPlayer.setOnErrorListener(onErrorListener); 148 | mPlayer.setOnPreparedListener(onPreparedListener); 149 | mPlayer.setScreenOnWhilePlaying(true);//在视频播放的时候保持屏幕的高亮 150 | //异步准备 151 | mPlayer.prepareAsync(); 152 | } catch (Exception e) { 153 | e.printStackTrace(); 154 | } 155 | } 156 | ``` 157 | ### 准备完成监听 158 | 159 | ```java 160 | private MediaPlayer.OnPreparedListener onPreparedListener = new MediaPlayer.OnPreparedListener() { 161 | @Override 162 | public void onPrepared(MediaPlayer mp) { 163 | //隐藏视频加载进度条 164 | mediaController.setPbLoadingVisiable(View.GONE); 165 | //进行视频的播放 166 | MediaHelper.play(); 167 | hasPlay = true; 168 | //隐藏标题 169 | mediaController.delayHideTitle(); 170 | //设置视频的总时长 171 | mediaController.setDuration(mPlayer.getDuration()); 172 | //更新播放的时间和进度 173 | mediaController.updatePlayTimeAndProgress(); 174 | } 175 | }; 176 | ``` 177 | ### 进行TextureView控件创建的监听 178 | 179 | ```java 180 | videoView.setSurfaceTextureListener(surfaceTextureListener); 181 | ``` 182 | 183 | ```java 184 | private TextureView.SurfaceTextureListener surfaceTextureListener = new TextureView.SurfaceTextureListener() { 185 | 186 | //创建完成 TextureView才可以进行视频画面的显示 187 | @Override 188 | public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { 189 | // Log.i(TAG,"onSurfaceTextureAvailable"); 190 | mSurface = new Surface(surface);//连接对象(MediaPlayer和TextureView) 191 | play(info.url); 192 | } 193 | 194 | @Override 195 | public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { 196 | // Log.i(TAG,"onSurfaceTextureSizeChanged"); 197 | } 198 | 199 | @Override 200 | public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { 201 | // Log.i(TAG,"onSurfaceTextureDestroyed"); 202 | return true; 203 | } 204 | 205 | @Override 206 | public void onSurfaceTextureUpdated(SurfaceTexture surface) { 207 | // Log.i(TAG,"onSurfaceTextureUpdated"); 208 | } 209 | }; 210 | ``` 211 | 212 | ## VideoMediaController 213 | 214 | 215 | 216 | 217 | 218 | 布局文件如下 219 | 220 | ```xml 221 | 222 | 227 | 228 | 229 | 235 | 236 | 242 | 243 | 248 | 249 | 255 | 256 | 261 | 262 | 270 | 271 | 272 | 277 | 278 | 283 | 284 | 292 | 293 | 294 | 295 | 296 | 305 | 306 | 313 | 314 | 329 | 330 | 340 | 341 | 349 | 350 | 359 | 360 | 368 | 369 | 374 | 375 | 376 | ``` 377 | 显示或者隐藏视频控制界面 378 | ```java 379 | private void showOrHideVideoController() { 380 | if(llPlayControl.getVisibility() == View.GONE){ 381 | //显示(标题、播放按钮、视频进度控制) 382 | tvTitle.setVisibility(View.VISIBLE); 383 | ivPlay.setVisibility(View.VISIBLE); 384 | //加载动画 385 | Animation animation = AnimationUtils.loadAnimation(getContext(),R.anim.bottom_enter); 386 | animation.setAnimationListener(new SimpleAnimationListener(){ 387 | @Override 388 | public void onAnimationEnd(Animation animation) { 389 | super.onAnimationEnd(animation); 390 | llPlayControl.setVisibility(View.VISIBLE); 391 | //过2秒后自动隐藏 392 | mHandler.sendEmptyMessageDelayed(MSG_HIDE_CONTROLLER,2000); 393 | } 394 | }); 395 | //执行动画 396 | llPlayControl.startAnimation(animation); 397 | }else{ 398 | //隐藏(标题、播放按钮、视频进度控制) 399 | tvTitle.setVisibility(View.GONE); 400 | ivPlay.setVisibility(View.GONE); 401 | //加载动画 402 | Animation animation = AnimationUtils.loadAnimation(getContext(),R.anim.bottom_exit); 403 | animation.setAnimationListener(new SimpleAnimationListener(){ 404 | @Override 405 | public void onAnimationEnd(Animation animation) { 406 | super.onAnimationEnd(animation); 407 | llPlayControl.setVisibility(View.GONE); 408 | } 409 | }); 410 | //执行动画 411 | llPlayControl.startAnimation(animation); 412 | } 413 | } 414 | ``` 415 | 416 | 更新播放的时间和进度 417 | 418 | ```java 419 | public void updatePlayTimeAndProgress() { 420 | //获取目前播放的进度 421 | int currentPosition = MediaHelper.getInstance().getCurrentPosition(); 422 | //格式化 423 | String useTime = formatDuration(currentPosition); 424 | tvUseTime.setText(useTime); 425 | //更新进度 426 | int duration = MediaHelper.getInstance().getDuration(); 427 | if(duration == 0){ 428 | return; 429 | } 430 | int progress = 100*currentPosition/duration; 431 | seekBar.setProgress(progress); 432 | //发送一个更新的延时消息 433 | mHandler.sendEmptyMessageDelayed(MSG_UPDATE_TIME_PROGRESS,500); 434 | } 435 | ``` 436 | ## 自定义SeekBar 437 | 438 | ```xml 439 | 448 | ``` 449 | 450 | sb_progress_drawable 451 | 452 | ```xml 453 | 454 | 455 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | ``` 479 | ## 列表的item滚动出屏幕时停止播放 480 | 481 | ```java 482 | private RecyclerView.OnScrollListener onScrollListener = new RecyclerView.OnScrollListener() { 483 | @Override 484 | public void onScrollStateChanged(RecyclerView recyclerView, int newState) { 485 | super.onScrollStateChanged(recyclerView, newState); 486 | } 487 | 488 | //进行滑动 489 | @Override 490 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) { 491 | super.onScrolled(recyclerView, dx, dy); 492 | //获取屏幕上显示的第一个条目和最后一个条目的下标 493 | int firstVisibleItemPosition = lm.findFirstVisibleItemPosition(); 494 | int lastVisibleItemPosition = lm.findLastVisibleItemPosition(); 495 | //获取播放条目的下标 496 | int currentPosition = adapter.currentPosition; 497 | if((firstVisibleItemPosition > currentPosition || lastVisibleItemPosition < currentPosition) && currentPosition > -1){ 498 | //让播放隐藏的条目停止 499 | MediaHelper.release(); 500 | adapter.currentPosition = -1; 501 | adapter.notifyDataSetChanged(); 502 | } 503 | } 504 | }; 505 | ``` -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | defaultConfig { 7 | applicationId "com.jackchan.videoplayer" 8 | minSdkVersion 14 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | testCompile 'junit:junit:4.12' 28 | compile 'com.android.support:appcompat-v7:25.3.1' 29 | compile 'com.android.support:recyclerview-v7:25.3.1' 30 | compile 'com.jakewharton:butterknife:8.6.0' 31 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0' 32 | } 33 | -------------------------------------------------------------------------------- /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 D:\android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/jackchan/videoplayer/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.jackchan.videoplayer; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.jackchan.videoplayer", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/jackchan/videoplayer/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.jackchan.videoplayer; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.support.v7.widget.LinearLayoutManager; 6 | import android.support.v7.widget.RecyclerView; 7 | 8 | import com.jackchan.videoplayer.adapter.VideoPlayListAdatper; 9 | import com.jackchan.videoplayer.bean.VideoPlayerItemInfo; 10 | import com.jackchan.videoplayer.utils.MediaHelper; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | import butterknife.BindView; 16 | import butterknife.ButterKnife; 17 | 18 | /** 19 | * ============================================================ 20 | * Copyright:JackChan和他的朋友们有限公司版权所有 (c) 2017 21 | * Author: JackChan 22 | * Email: 815712739@qq.com 23 | * GitHub: https://github.com/JackChan1999 24 | * GitBook: https://www.gitbook.com/@alleniverson 25 | * CSDN博客: http://blog.csdn.net/axi295309066 26 | * 个人博客: https://jackchan1999.github.io/ 27 | * 微博: AndroidDeveloper 28 | *

29 | * Project_Name:VideoPlayer 30 | * Package_Name:com.jackchan.videoplayer 31 | * Version:1.0 32 | * time:2017/5/24 18:05 33 | * des :TextureView+MediaPlayer在线短视频播放 34 | * gitVersion:2.12.0.windows.1 35 | * updateAuthor:AllenIverson 36 | * updateDate:2017/5/24 18:05 37 | * updateDes:${TODO} 38 | * ============================================================ 39 | */ 40 | 41 | public class MainActivity extends AppCompatActivity { 42 | 43 | @BindView(R.id.rv) 44 | RecyclerView rv; 45 | 46 | private List videoPlayerItemInfoList; 47 | private LinearLayoutManager lm; 48 | private VideoPlayListAdatper adapter; 49 | 50 | @Override 51 | protected void onCreate(Bundle savedInstanceState) { 52 | super.onCreate(savedInstanceState); 53 | 54 | initViews(); 55 | initData(); 56 | initRecyclerView(); 57 | } 58 | 59 | private void initRecyclerView() { 60 | //初始化RecyclerView 61 | lm = new LinearLayoutManager(this); 62 | rv.setLayoutManager(lm); 63 | 64 | // 添加分割线 65 | // rv.addItemDecoration(new RecycleViewDivider(this,LinearLayoutManager.HORIZONTAL,1, Color.BLACK)); 66 | 67 | adapter = new VideoPlayListAdatper(this, videoPlayerItemInfoList); 68 | rv.setAdapter(adapter); 69 | //设置滑动监听 70 | rv.addOnScrollListener(onScrollListener); 71 | } 72 | 73 | private void initViews() { 74 | setContentView(R.layout.activity_main); 75 | ButterKnife.bind(this); 76 | } 77 | 78 | private void initData() { 79 | //网络视频路径 80 | String url = "http://ips.ifeng.com/video19.ifeng.com/video09/2017/05/24/4664192-102-008-1012.mp4"; 81 | 82 | //数据的初始化 83 | videoPlayerItemInfoList = new ArrayList<>(); 84 | for (int i = 0; i < 20; i++) { 85 | videoPlayerItemInfoList.add(new VideoPlayerItemInfo(i,url)); 86 | } 87 | } 88 | 89 | private RecyclerView.OnScrollListener onScrollListener = new RecyclerView.OnScrollListener() { 90 | @Override 91 | public void onScrollStateChanged(RecyclerView recyclerView, int newState) { 92 | super.onScrollStateChanged(recyclerView, newState); 93 | } 94 | 95 | //进行滑动 96 | @Override 97 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) { 98 | super.onScrolled(recyclerView, dx, dy); 99 | //获取屏幕上显示的第一个条目和最后一个条目的下标 100 | int firstVisibleItemPosition = lm.findFirstVisibleItemPosition(); 101 | int lastVisibleItemPosition = lm.findLastVisibleItemPosition(); 102 | //获取播放条目的下标 103 | int currentPosition = adapter.currentPosition; 104 | if((firstVisibleItemPosition > currentPosition || lastVisibleItemPosition < currentPosition) && currentPosition > -1){ 105 | //让播放隐藏的条目停止 106 | MediaHelper.release(); 107 | adapter.currentPosition = -1; 108 | adapter.notifyDataSetChanged(); 109 | } 110 | } 111 | }; 112 | 113 | } 114 | -------------------------------------------------------------------------------- /app/src/main/java/com/jackchan/videoplayer/adapter/VideoPlayListAdatper.java: -------------------------------------------------------------------------------- 1 | package com.jackchan.videoplayer.adapter; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.ImageView; 9 | import android.widget.TextView; 10 | 11 | import com.jackchan.videoplayer.R; 12 | import com.jackchan.videoplayer.bean.VideoPlayerItemInfo; 13 | import com.jackchan.videoplayer.view.VideoPlayer; 14 | 15 | import java.util.List; 16 | 17 | import butterknife.BindView; 18 | import butterknife.ButterKnife; 19 | 20 | /** 21 | * ============================================================ 22 | * Copyright:JackChan和他的朋友们有限公司版权所有 (c) 2017 23 | * Author: JackChan 24 | * Email: 815712739@qq.com 25 | * GitHub: https://github.com/JackChan1999 26 | * GitBook: https://www.gitbook.com/@alleniverson 27 | * CSDN博客: http://blog.csdn.net/axi295309066 28 | * 个人博客: https://jackchan1999.github.io/ 29 | * 微博: AndroidDeveloper 30 | *

31 | * Project_Name:VideoPlayer 32 | * Package_Name:com.jackchan.videoplayer 33 | * Version:1.0 34 | * time:2017/5/24 18:05 35 | * des :adapter 36 | * gitVersion:2.12.0.windows.1 37 | * updateAuthor:AllenIverson 38 | * updateDate:2017/5/24 18:05 39 | * updateDes:${TODO} 40 | * ============================================================ 41 | */ 42 | 43 | public class VideoPlayListAdatper extends RecyclerView.Adapter { 44 | 45 | private Context context; 46 | private List videoPlayerItemInfoList; 47 | 48 | //记录之前播放的条目下标 49 | public int currentPosition = -1; 50 | public VideoPlayListAdatper(Context context, List videoPlayerItemInfoList) { 51 | this.context = context; 52 | this.videoPlayerItemInfoList = videoPlayerItemInfoList; 53 | } 54 | 55 | @Override 56 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 57 | View view = LayoutInflater.from(context).inflate(R.layout.item_video_play, parent, false); 58 | ListViewHolder viewHolder = new ListViewHolder(view); 59 | return viewHolder; 60 | } 61 | 62 | @Override 63 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 64 | final ListViewHolder viewHolder = (ListViewHolder) holder; 65 | //获取到条目对应的数据 66 | VideoPlayerItemInfo info = videoPlayerItemInfoList.get(position); 67 | //传递给条目里面的MyVideoPlayer 68 | viewHolder.videoPlayer.setPlayData(info); 69 | //把条目的下标传递给MyVideoMediaController对象 70 | viewHolder.videoPlayer.mediaController.setPosition(position); 71 | //把Adapter对象传递给MyVideoMediaController对象 72 | viewHolder.videoPlayer.mediaController.setAdapter(this); 73 | if(position != currentPosition){ 74 | //设置为初始化状态 75 | viewHolder.videoPlayer.initViewDisplay(); 76 | } 77 | } 78 | 79 | @Override 80 | public int getItemCount() { 81 | return videoPlayerItemInfoList != null ? videoPlayerItemInfoList.size() : 0; 82 | } 83 | 84 | public void setPlayPosition(int position) { 85 | currentPosition = position; 86 | } 87 | 88 | 89 | static class ListViewHolder extends RecyclerView.ViewHolder{ 90 | @BindView(R.id.iv_bg) 91 | ImageView ivBg; 92 | @BindView(R.id.videoPlayer) 93 | VideoPlayer videoPlayer; 94 | @BindView(R.id.iv_author) 95 | ImageView ivAuthor; 96 | @BindView(R.id.tv_author_name) 97 | TextView tvAuthorName; 98 | @BindView(R.id.tv_play_count) 99 | TextView tvPlayCount; 100 | @BindView(R.id.iv_comment) 101 | ImageView ivComment; 102 | @BindView(R.id.tv_comment_count) 103 | TextView tvCommentCount; 104 | @BindView(R.id.iv_comment_more) 105 | ImageView ivCommentMore; 106 | 107 | ListViewHolder(View view) { 108 | super(view); 109 | ButterKnife.bind(this, view); 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /app/src/main/java/com/jackchan/videoplayer/bean/VideoPlayerItemInfo.java: -------------------------------------------------------------------------------- 1 | package com.jackchan.videoplayer.bean; 2 | 3 | /** 4 | * ============================================================ 5 | * Copyright:JackChan和他的朋友们有限公司版权所有 (c) 2017 6 | * Author: JackChan 7 | * Email: 815712739@qq.com 8 | * GitHub: https://github.com/JackChan1999 9 | * GitBook: https://www.gitbook.com/@alleniverson 10 | * CSDN博客: http://blog.csdn.net/axi295309066 11 | * 个人博客: https://jackchan1999.github.io/ 12 | * 微博: AndroidDeveloper 13 | *

14 | * Project_Name:VideoPlayer 15 | * Package_Name:com.jackchan.videoplayer 16 | * Version:1.0 17 | * time:2017/5/24 18:05 18 | * des :列表实体类 19 | * gitVersion:2.12.0.windows.1 20 | * updateAuthor:AllenIverson 21 | * updateDate:2017/5/24 18:05 22 | * updateDes:${TODO} 23 | * ============================================================ 24 | */ 25 | 26 | public class VideoPlayerItemInfo { 27 | public int id; 28 | public String url; 29 | //... 30 | 31 | public VideoPlayerItemInfo(int id, String url) { 32 | this.id = id; 33 | this.url = url; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/java/com/jackchan/videoplayer/utils/MediaHelper.java: -------------------------------------------------------------------------------- 1 | package com.jackchan.videoplayer.utils; 2 | 3 | import android.media.MediaPlayer; 4 | 5 | /** 6 | * ============================================================ 7 | * Copyright:JackChan和他的朋友们有限公司版权所有 (c) 2017 8 | * Author: JackChan 9 | * Email: 815712739@qq.com 10 | * GitHub: https://github.com/JackChan1999 11 | * GitBook: https://www.gitbook.com/@alleniverson 12 | * CSDN博客: http://blog.csdn.net/axi295309066 13 | * 个人博客: https://jackchan1999.github.io/ 14 | * 微博: AndroidDeveloper 15 | *

16 | * Project_Name:VideoPlayer 17 | * Package_Name:com.jackchan.videoplayer 18 | * Version:1.0 19 | * time:2017/5/24 18:05 20 | * des :多媒体的工具类 21 | * gitVersion:2.12.0.windows.1 22 | * updateAuthor:AllenIverson 23 | * updateDate:2017/5/24 18:05 24 | * updateDes:${TODO} 25 | * ============================================================ 26 | */ 27 | public final class MediaHelper { 28 | 29 | private MediaHelper() { 30 | } 31 | 32 | private static MediaPlayer mPlayer; 33 | 34 | //获取多媒体对象 35 | public static MediaPlayer getInstance(){ 36 | if(mPlayer == null){ 37 | synchronized (MediaHelper.class){ 38 | if (mPlayer == null){ 39 | mPlayer = new MediaPlayer(); 40 | } 41 | } 42 | } 43 | return mPlayer; 44 | } 45 | 46 | //播放 47 | public static void play(){ 48 | if(mPlayer != null){ 49 | mPlayer.start(); 50 | } 51 | } 52 | 53 | //暂停 54 | public static void pause(){ 55 | if(mPlayer != null){ 56 | mPlayer.pause(); 57 | } 58 | } 59 | 60 | //释放 61 | public static void release(){ 62 | if(mPlayer != null){ 63 | mPlayer.release(); 64 | mPlayer = null; 65 | } 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /app/src/main/java/com/jackchan/videoplayer/view/RecycleViewDivider.java: -------------------------------------------------------------------------------- 1 | package com.jackchan.videoplayer.view; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Canvas; 6 | import android.graphics.Paint; 7 | import android.graphics.Rect; 8 | import android.graphics.drawable.Drawable; 9 | import android.support.v4.content.ContextCompat; 10 | import android.support.v7.widget.LinearLayoutManager; 11 | import android.support.v7.widget.RecyclerView; 12 | import android.view.View; 13 | 14 | /** 15 | * ============================================================ 16 | * Copyright:JackChan和他的朋友们有限公司版权所有 (c) 2017 17 | * Author: JackChan 18 | * Email: 815712739@qq.com 19 | * GitHub: https://github.com/JackChan1999 20 | * GitBook: https://www.gitbook.com/@alleniverson 21 | * CSDN博客: http://blog.csdn.net/axi295309066 22 | * 个人博客: https://jackchan1999.github.io/ 23 | * 微博: AndroidDeveloper 24 | *

25 | * Project_Name:VideoPlayer 26 | * Package_Name:com.jackchan.videoplayer 27 | * Version:1.0 28 | * time:2017/5/24 18:05 29 | * des :Recyclerview分割线 30 | * gitVersion:2.12.0.windows.1 31 | * updateAuthor:AllenIverson 32 | * updateDate:2017/5/24 18:05 33 | * updateDes:${TODO} 34 | * ============================================================ 35 | */ 36 | 37 | public class RecycleViewDivider extends RecyclerView.ItemDecoration { 38 | 39 | private Paint mPaint; 40 | private Drawable mDivider; 41 | private int mDividerHeight = 2;//分割线高度,默认为1px 42 | private int mOrientation;//列表的方向:LinearLayoutManager.VERTICAL或LinearLayoutManager.HORIZONTAL 43 | private static final int[] ATTRS = new int[]{android.R.attr.listDivider}; 44 | 45 | /** 46 | * 默认分割线:高度为2px,颜色为灰色 47 | * 48 | * @param context 49 | * @param orientation 列表方向 50 | */ 51 | public RecycleViewDivider(Context context, int orientation) { 52 | if (orientation != LinearLayoutManager.VERTICAL && orientation != LinearLayoutManager.HORIZONTAL) { 53 | throw new IllegalArgumentException("请输入正确的参数!"); 54 | } 55 | mOrientation = orientation; 56 | final TypedArray a = context.obtainStyledAttributes(ATTRS); 57 | mDivider = a.getDrawable(0); 58 | a.recycle(); 59 | } 60 | 61 | /** 62 | * 自定义分割线 63 | * 64 | * @param context 65 | * @param orientation 列表方向 66 | * @param drawableId 分割线图片 67 | */ 68 | public RecycleViewDivider(Context context, int orientation, int drawableId) { 69 | this(context, orientation); 70 | mDivider = ContextCompat.getDrawable(context, drawableId); 71 | mDividerHeight = mDivider.getIntrinsicHeight(); 72 | } 73 | 74 | /** 75 | * 自定义分割线 76 | * 77 | * @param context 78 | * @param orientation 列表方向 79 | * @param dividerHeight 分割线高度 80 | * @param dividerColor 分割线颜色 81 | */ 82 | public RecycleViewDivider(Context context, int orientation, int dividerHeight, int dividerColor) { 83 | this(context, orientation); 84 | mDividerHeight = dividerHeight; 85 | mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 86 | mPaint.setColor(dividerColor); 87 | mPaint.setStyle(Paint.Style.FILL); 88 | } 89 | 90 | 91 | //获取分割线尺寸 92 | @Override 93 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { 94 | super.getItemOffsets(outRect, view, parent, state); 95 | outRect.set(0, 0, 0, mDividerHeight); 96 | } 97 | 98 | //绘制分割线 99 | @Override 100 | public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { 101 | super.onDraw(c, parent, state); 102 | if (mOrientation == LinearLayoutManager.VERTICAL) { 103 | drawVertical(c, parent); 104 | } else { 105 | drawHorizontal(c, parent); 106 | } 107 | } 108 | 109 | //绘制横向 item 分割线 110 | private void drawHorizontal(Canvas canvas, RecyclerView parent) { 111 | final int left = parent.getPaddingLeft(); 112 | final int right = parent.getMeasuredWidth() - parent.getPaddingRight(); 113 | final int childSize = parent.getChildCount(); 114 | for (int i = 0; i < childSize; i++) { 115 | final View child = parent.getChildAt(i); 116 | RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams(); 117 | final int top = child.getBottom() + layoutParams.bottomMargin; 118 | final int bottom = top + mDividerHeight; 119 | if (mDivider != null) { 120 | mDivider.setBounds(left, top, right, bottom); 121 | mDivider.draw(canvas); 122 | } 123 | if (mPaint != null) { 124 | canvas.drawRect(left, top, right, bottom, mPaint); 125 | } 126 | } 127 | } 128 | 129 | //绘制纵向 item 分割线 130 | private void drawVertical(Canvas canvas, RecyclerView parent) { 131 | final int top = parent.getPaddingTop(); 132 | final int bottom = parent.getMeasuredHeight() - parent.getPaddingBottom(); 133 | final int childSize = parent.getChildCount(); 134 | for (int i = 0; i < childSize; i++) { 135 | final View child = parent.getChildAt(i); 136 | RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams(); 137 | final int left = child.getRight() + layoutParams.rightMargin; 138 | final int right = left + mDividerHeight; 139 | if (mDivider != null) { 140 | mDivider.setBounds(left, top, right, bottom); 141 | mDivider.draw(canvas); 142 | } 143 | if (mPaint != null) { 144 | canvas.drawRect(left, top, right, bottom, mPaint); 145 | } 146 | } 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /app/src/main/java/com/jackchan/videoplayer/view/VideoMediaController.java: -------------------------------------------------------------------------------- 1 | package com.jackchan.videoplayer.view; 2 | 3 | import android.content.Context; 4 | import android.os.Handler; 5 | import android.os.Message; 6 | import android.util.AttributeSet; 7 | import android.util.Log; 8 | import android.view.MotionEvent; 9 | import android.view.View; 10 | import android.view.animation.Animation; 11 | import android.view.animation.AnimationUtils; 12 | import android.widget.ImageView; 13 | import android.widget.LinearLayout; 14 | import android.widget.ProgressBar; 15 | import android.widget.RelativeLayout; 16 | import android.widget.SeekBar; 17 | import android.widget.TextView; 18 | 19 | import com.jackchan.videoplayer.R; 20 | import com.jackchan.videoplayer.adapter.VideoPlayListAdatper; 21 | import com.jackchan.videoplayer.utils.MediaHelper; 22 | 23 | import java.text.SimpleDateFormat; 24 | import java.util.Date; 25 | 26 | import butterknife.BindView; 27 | import butterknife.ButterKnife; 28 | import butterknife.OnClick; 29 | 30 | /** 31 | * ============================================================ 32 | * Copyright:JackChan和他的朋友们有限公司版权所有 (c) 2017 33 | * Author: JackChan 34 | * Email: 815712739@qq.com 35 | * GitHub: https://github.com/JackChan1999 36 | * GitBook: https://www.gitbook.com/@alleniverson 37 | * CSDN博客: http://blog.csdn.net/axi295309066 38 | * 个人博客: https://jackchan1999.github.io/ 39 | * 微博: AndroidDeveloper 40 | *

41 | * Project_Name:VideoPlayer 42 | * Package_Name:com.jackchan.videoplayer 43 | * Version:1.0 44 | * time:2017/5/24 18:05 45 | * des :对应视频播放控制界面的封装 46 | * gitVersion:2.12.0.windows.1 47 | * updateAuthor:AllenIverson 48 | * updateDate:2017/5/24 18:05 49 | * updateDes:${TODO} 50 | * ============================================================ 51 | */ 52 | 53 | public class VideoMediaController extends RelativeLayout { 54 | 55 | private static final String TAG = "VideoMediaController"; 56 | @BindView(R.id.pb_loading) 57 | ProgressBar pbLoading; 58 | @BindView(R.id.iv_replay) 59 | ImageView ivReplay; 60 | @BindView(R.id.iv_share) 61 | ImageView ivShare; 62 | @BindView(R.id.rl_play_finish) 63 | RelativeLayout rlPlayFinish; 64 | @BindView(R.id.tv_title) 65 | TextView tvTitle; 66 | @BindView(R.id.iv_play) 67 | ImageView ivPlay; 68 | @BindView(R.id.tv_all_time) 69 | TextView tvAllTime; 70 | @BindView(R.id.tv_use_time) 71 | TextView tvUseTime; 72 | @BindView(R.id.seekBar) 73 | SeekBar seekBar; 74 | @BindView(R.id.tv_time) 75 | TextView tvTime; 76 | @BindView(R.id.iv_fullscreen) 77 | ImageView ivFullscreen; 78 | @BindView(R.id.ll_play_control) 79 | LinearLayout llPlayControl; 80 | 81 | private boolean hasPause;//是否暂停 82 | 83 | private static final int MSG_HIDE_TITLE = 0; 84 | private static final int MSG_UPDATE_TIME_PROGRESS = 1; 85 | private static final int MSG_HIDE_CONTROLLER = 2; 86 | //消息处理器 87 | private Handler mHandler = new Handler(){ 88 | @Override 89 | public void handleMessage(Message msg) { 90 | super.handleMessage(msg); 91 | switch (msg.what){ 92 | case MSG_HIDE_TITLE: 93 | tvTitle.setVisibility(View.GONE); 94 | break; 95 | case MSG_UPDATE_TIME_PROGRESS: 96 | updatePlayTimeAndProgress(); 97 | break; 98 | case MSG_HIDE_CONTROLLER: 99 | showOrHideVideoController(); 100 | break; 101 | } 102 | } 103 | }; 104 | 105 | public void delayHideTitle(){ 106 | //移除消息 107 | mHandler.removeMessages(MSG_HIDE_TITLE); 108 | //发送一个空的延时2秒消息 109 | mHandler.sendEmptyMessageDelayed(MSG_HIDE_TITLE,2000); 110 | } 111 | 112 | public VideoMediaController(Context context) { 113 | this(context, null); 114 | } 115 | 116 | public VideoMediaController(Context context, AttributeSet attrs) { 117 | this(context, attrs, 0); 118 | } 119 | 120 | public VideoMediaController(Context context, AttributeSet attrs, int defStyleAttr) { 121 | super(context, attrs, defStyleAttr); 122 | initView(); 123 | } 124 | 125 | //初始化控件 126 | private void initView() { 127 | View view = View.inflate(getContext(), R.layout.video_controller, this); 128 | ButterKnife.bind(this,view); 129 | 130 | initViewDisplay(); 131 | //设置视频播放时的点击界面 132 | setOnTouchListener(onTouchListener); 133 | //设置SeekBar的拖动监听 134 | seekBar.setOnSeekBarChangeListener(onSeekBarChangeListener); 135 | //播放完成的界面要销毁触摸事件 136 | rlPlayFinish.setOnTouchListener(new OnTouchListener() { 137 | @Override 138 | public boolean onTouch(View v, MotionEvent event) { 139 | return true; 140 | } 141 | }); 142 | } 143 | 144 | private SeekBar.OnSeekBarChangeListener onSeekBarChangeListener = new SeekBar.OnSeekBarChangeListener() { 145 | //拖动的过程中调用 146 | @Override 147 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 148 | 149 | } 150 | 151 | //开始拖动的时候调用 152 | @Override 153 | public void onStartTrackingTouch(SeekBar seekBar) { 154 | //暂停视频的播放、停止时间和进度条的更新 155 | MediaHelper.pause(); 156 | mHandler.removeMessages(MSG_UPDATE_TIME_PROGRESS); 157 | } 158 | 159 | //停止拖动时调用 160 | @Override 161 | public void onStopTrackingTouch(SeekBar seekBar) { 162 | //把视频跳转到对应的位置 163 | int progress = seekBar.getProgress(); 164 | int duration = myVideoPlayer.mPlayer.getDuration(); 165 | int position = duration * progress / 100; 166 | myVideoPlayer.mPlayer.seekTo(position); 167 | //开始播放、开始时间和进度条的更新 168 | MediaHelper.play(); 169 | updatePlayTimeAndProgress(); 170 | } 171 | }; 172 | 173 | 174 | private OnTouchListener onTouchListener = new OnTouchListener() { 175 | @Override 176 | public boolean onTouch(View v, MotionEvent event) { 177 | //按下+已经播放了 178 | if(event.getAction() == MotionEvent.ACTION_DOWN && myVideoPlayer.hasPlay){ 179 | //显示或者隐藏视频控制界面 180 | showOrHideVideoController(); 181 | } 182 | return true;//去处理事件 183 | } 184 | }; 185 | //显示或者隐藏视频控制界面 186 | private void showOrHideVideoController() { 187 | if(llPlayControl.getVisibility() == View.GONE){ 188 | //显示(标题、播放按钮、视频进度控制) 189 | tvTitle.setVisibility(View.VISIBLE); 190 | ivPlay.setVisibility(View.VISIBLE); 191 | //加载动画 192 | Animation animation = AnimationUtils.loadAnimation(getContext(),R.anim.bottom_enter); 193 | animation.setAnimationListener(new SimpleAnimationListener(){ 194 | @Override 195 | public void onAnimationEnd(Animation animation) { 196 | super.onAnimationEnd(animation); 197 | llPlayControl.setVisibility(View.VISIBLE); 198 | //过2秒后自动隐藏 199 | mHandler.sendEmptyMessageDelayed(MSG_HIDE_CONTROLLER,2000); 200 | } 201 | }); 202 | //执行动画 203 | llPlayControl.startAnimation(animation); 204 | }else{ 205 | //隐藏(标题、播放按钮、视频进度控制) 206 | tvTitle.setVisibility(View.GONE); 207 | ivPlay.setVisibility(View.GONE); 208 | //加载动画 209 | Animation animation = AnimationUtils.loadAnimation(getContext(),R.anim.bottom_exit); 210 | animation.setAnimationListener(new SimpleAnimationListener(){ 211 | @Override 212 | public void onAnimationEnd(Animation animation) { 213 | super.onAnimationEnd(animation); 214 | llPlayControl.setVisibility(View.GONE); 215 | } 216 | }); 217 | //执行动画 218 | llPlayControl.startAnimation(animation); 219 | } 220 | } 221 | 222 | //更新进度条的第二进度(缓存) 223 | public void updateSeekBarSecondProgress(int percent) { 224 | seekBar.setSecondaryProgress(percent); 225 | } 226 | 227 | //设置播放视频的总时长 228 | public void setDuration(int duration) { 229 | String time = formatDuration(duration); 230 | tvTime.setText(time); 231 | tvUseTime.setText("00:00"); 232 | } 233 | 234 | //格式化时间 00:00 235 | public String formatDuration(int duration){ 236 | SimpleDateFormat format = new SimpleDateFormat("mm:ss"); 237 | return format.format(new Date(duration)); 238 | } 239 | 240 | //更新播放的时间和进度 241 | public void updatePlayTimeAndProgress() { 242 | //获取目前播放的进度 243 | int currentPosition = MediaHelper.getInstance().getCurrentPosition(); 244 | //格式化 245 | String useTime = formatDuration(currentPosition); 246 | tvUseTime.setText(useTime); 247 | //更新进度 248 | int duration = MediaHelper.getInstance().getDuration(); 249 | if(duration == 0){ 250 | return; 251 | } 252 | int progress = 100*currentPosition/duration; 253 | seekBar.setProgress(progress); 254 | //发送一个更新的延时消息 255 | mHandler.sendEmptyMessageDelayed(MSG_UPDATE_TIME_PROGRESS,500); 256 | } 257 | 258 | //移除所有的消息 259 | public void removeAllMessage(){ 260 | mHandler.removeCallbacksAndMessages(null); 261 | } 262 | 263 | //显示视频播放完成的界面 264 | public void showPlayFinishView() { 265 | tvTitle.setVisibility(View.VISIBLE); 266 | rlPlayFinish.setVisibility(View.VISIBLE); 267 | tvAllTime.setVisibility(View.VISIBLE); 268 | } 269 | 270 | private int position; 271 | public void setPosition(int position) { 272 | this.position = position; 273 | } 274 | 275 | private VideoPlayListAdatper adapter; 276 | public void setAdapter(VideoPlayListAdatper videoPlayListAdatper) { 277 | this.adapter = videoPlayListAdatper; 278 | } 279 | 280 | //简单的动画监听器(不需要其他的监听器去实现多余的方法) 281 | private class SimpleAnimationListener implements Animation.AnimationListener{ 282 | 283 | @Override 284 | public void onAnimationStart(Animation animation) { 285 | 286 | } 287 | 288 | @Override 289 | public void onAnimationEnd(Animation animation) { 290 | 291 | } 292 | 293 | @Override 294 | public void onAnimationRepeat(Animation animation) { 295 | 296 | } 297 | } 298 | 299 | //初始化控件的显示状态 300 | public void initViewDisplay() { 301 | tvTitle.setVisibility(View.VISIBLE); 302 | ivPlay.setVisibility(View.VISIBLE); 303 | ivPlay.setImageResource(R.drawable.new_play_video); 304 | tvAllTime.setVisibility(View.VISIBLE); 305 | pbLoading.setVisibility(View.GONE); 306 | llPlayControl.setVisibility(View.GONE); 307 | rlPlayFinish.setVisibility(View.GONE); 308 | tvUseTime.setText("00:00"); 309 | seekBar.setProgress(0); 310 | seekBar.setSecondaryProgress(0); 311 | } 312 | 313 | @OnClick({R.id.iv_replay, R.id.iv_share, R.id.iv_play, R.id.iv_fullscreen}) 314 | public void onClick(View view) { 315 | switch (view.getId()) { 316 | case R.id.iv_replay: 317 | //隐藏播放完成界面 318 | rlPlayFinish.setVisibility(View.GONE); 319 | //隐藏时间 320 | tvAllTime.setVisibility(View.GONE); 321 | tvUseTime.setText("00:00"); 322 | //进度条 323 | seekBar.setProgress(0); 324 | //把媒体播放器的位置移动到开始的位置 325 | MediaHelper.getInstance().seekTo(0); 326 | //开始播放 327 | MediaHelper.play(); 328 | //延时隐藏标题 329 | delayHideTitle(); 330 | break; 331 | case R.id.iv_share: 332 | break; 333 | case R.id.iv_play: 334 | 335 | //点击一个新的条目进行播放 336 | //点击的条目下标是否是之前播放的条目下标 337 | if(position != adapter.currentPosition && adapter.currentPosition != -1 ){ 338 | Log.i(TAG,"点击了其他的条目"); 339 | 340 | //让其他的条目停止播放(还原条目开始的状态) 341 | MediaHelper.release(); 342 | //把播放条目的下标设置给适配器 343 | adapter.setPlayPosition(position); 344 | //刷新显示 345 | adapter.notifyDataSetChanged(); 346 | //播放 347 | ivPlay.setVisibility(View.GONE); 348 | tvAllTime.setVisibility(View.GONE); 349 | pbLoading.setVisibility(View.VISIBLE); 350 | //视频播放界面也需要显示 351 | myVideoPlayer.setVideoViewVisiable(View.VISIBLE); 352 | ivPlay.setImageResource(R.drawable.new_pause_video); 353 | return; 354 | } 355 | 356 | if(MediaHelper.getInstance().isPlaying()){ 357 | //暂停 358 | MediaHelper.pause(); 359 | //移除隐藏Controller布局的消息 360 | mHandler.removeMessages(MSG_HIDE_CONTROLLER); 361 | //移除更新播放时间和进度的消息 362 | mHandler.removeMessages(MSG_UPDATE_TIME_PROGRESS); 363 | ivPlay.setImageResource(R.drawable.new_play_video); 364 | hasPause = true; 365 | }else{ 366 | if(hasPause){ 367 | //继续播放 368 | MediaHelper.play(); 369 | mHandler.sendEmptyMessageDelayed(MSG_HIDE_CONTROLLER,2000); 370 | updatePlayTimeAndProgress(); 371 | hasPause = false; 372 | }else{ 373 | //播放 374 | ivPlay.setVisibility(View.GONE); 375 | tvAllTime.setVisibility(View.GONE); 376 | pbLoading.setVisibility(View.VISIBLE); 377 | //视频播放界面也需要显示 378 | myVideoPlayer.setVideoViewVisiable(View.VISIBLE); 379 | //把播放条目的下标设置给适配器 380 | adapter.setPlayPosition(position); 381 | } 382 | ivPlay.setImageResource(R.drawable.new_pause_video); 383 | } 384 | 385 | 386 | break; 387 | case R.id.iv_fullscreen: 388 | break; 389 | } 390 | } 391 | 392 | private VideoPlayer myVideoPlayer; 393 | public void setVideoPlayer(VideoPlayer myVideoPlayer) { 394 | this.myVideoPlayer = myVideoPlayer; 395 | } 396 | 397 | //设置视频加载进度条的显示状态 398 | public void setPbLoadingVisiable(int visiable) { 399 | pbLoading.setVisibility(visiable); 400 | } 401 | } 402 | -------------------------------------------------------------------------------- /app/src/main/java/com/jackchan/videoplayer/view/VideoPlayer.java: -------------------------------------------------------------------------------- 1 | package com.jackchan.videoplayer.view; 2 | 3 | import android.content.Context; 4 | import android.graphics.SurfaceTexture; 5 | import android.media.MediaPlayer; 6 | import android.util.AttributeSet; 7 | import android.view.Surface; 8 | import android.view.TextureView; 9 | import android.view.View; 10 | import android.widget.RelativeLayout; 11 | 12 | import com.jackchan.videoplayer.R; 13 | import com.jackchan.videoplayer.bean.VideoPlayerItemInfo; 14 | import com.jackchan.videoplayer.utils.MediaHelper; 15 | 16 | import butterknife.BindView; 17 | import butterknife.ButterKnife; 18 | 19 | /** 20 | * ============================================================ 21 | * Copyright:JackChan和他的朋友们有限公司版权所有 (c) 2017 22 | * Author: JackChan 23 | * Email: 815712739@qq.com 24 | * GitHub: https://github.com/JackChan1999 25 | * GitBook: https://www.gitbook.com/@alleniverson 26 | * CSDN博客: http://blog.csdn.net/axi295309066 27 | * 个人博客: https://jackchan1999.github.io/ 28 | * 微博: AndroidDeveloper 29 | *

30 | * Project_Name:VideoPlayer 31 | * Package_Name:com.jackchan.videoplayer 32 | * Version:1.0 33 | * time:2017/5/24 18:05 34 | * des :对于视频播放界面的一个封装类 35 | * gitVersion:2.12.0.windows.1 36 | * updateAuthor:AllenIverson 37 | * updateDate:2017/5/24 18:05 38 | * updateDes:${TODO} 39 | * ============================================================ 40 | */ 41 | 42 | public class VideoPlayer extends RelativeLayout { 43 | private static final String TAG = "VideoPlayer"; 44 | @BindView(R.id.video_view) 45 | public TextureView videoView; 46 | @BindView(R.id.mediaController) 47 | public VideoMediaController mediaController; 48 | 49 | public MediaPlayer mPlayer; 50 | private Surface mSurface; 51 | 52 | public boolean hasPlay;//是否播放了 53 | 54 | public VideoPlayer(Context context) { 55 | this(context, null); 56 | } 57 | 58 | public VideoPlayer(Context context, AttributeSet attrs) { 59 | this(context, attrs, 0); 60 | } 61 | 62 | public VideoPlayer(Context context, AttributeSet attrs, int defStyleAttr) { 63 | super(context, attrs, defStyleAttr); 64 | initView(); 65 | } 66 | 67 | //初始化布局 68 | private void initView() { 69 | View view = View.inflate(getContext(), R.layout.video_play, this); 70 | ButterKnife.bind(this,view); 71 | 72 | initViewDisplay(); 73 | //把VideoPlayer对象传递给VideoMediaController 74 | mediaController.setVideoPlayer(this); 75 | 76 | //进行TextureView控件创建的监听 77 | videoView.setSurfaceTextureListener(surfaceTextureListener); 78 | } 79 | 80 | private TextureView.SurfaceTextureListener surfaceTextureListener = new TextureView.SurfaceTextureListener() { 81 | 82 | //创建完成 TextureView才可以进行视频画面的显示 83 | @Override 84 | public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { 85 | // Log.i(TAG,"onSurfaceTextureAvailable"); 86 | mSurface = new Surface(surface);//连接对象(MediaPlayer和TextureView) 87 | play(info.url); 88 | } 89 | 90 | @Override 91 | public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { 92 | // Log.i(TAG,"onSurfaceTextureSizeChanged"); 93 | } 94 | 95 | @Override 96 | public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { 97 | // Log.i(TAG,"onSurfaceTextureDestroyed"); 98 | return true; 99 | } 100 | 101 | @Override 102 | public void onSurfaceTextureUpdated(SurfaceTexture surface) { 103 | // Log.i(TAG,"onSurfaceTextureUpdated"); 104 | } 105 | }; 106 | 107 | //视频播放(视频的初始化) 108 | private void play(String url){ 109 | try { 110 | mPlayer = MediaHelper.getInstance(); 111 | mPlayer.reset(); 112 | mPlayer.setDataSource(url); 113 | //让MediaPlayer和TextureView进行视频画面的结合 114 | mPlayer.setSurface(mSurface); 115 | //设置监听 116 | mPlayer.setOnBufferingUpdateListener(onBufferingUpdateListener); 117 | mPlayer.setOnCompletionListener(onCompletionListener); 118 | mPlayer.setOnErrorListener(onErrorListener); 119 | mPlayer.setOnPreparedListener(onPreparedListener); 120 | mPlayer.setScreenOnWhilePlaying(true);//在视频播放的时候保持屏幕的高亮 121 | //异步准备 122 | mPlayer.prepareAsync(); 123 | } catch (Exception e) { 124 | e.printStackTrace(); 125 | } 126 | } 127 | 128 | //准备完成监听 129 | private MediaPlayer.OnPreparedListener onPreparedListener = new MediaPlayer.OnPreparedListener() { 130 | @Override 131 | public void onPrepared(MediaPlayer mp) { 132 | //隐藏视频加载进度条 133 | mediaController.setPbLoadingVisiable(View.GONE); 134 | //进行视频的播放 135 | MediaHelper.play(); 136 | hasPlay = true; 137 | //隐藏标题 138 | mediaController.delayHideTitle(); 139 | //设置视频的总时长 140 | mediaController.setDuration(mPlayer.getDuration()); 141 | //更新播放的时间和进度 142 | mediaController.updatePlayTimeAndProgress(); 143 | } 144 | }; 145 | 146 | //错误监听 147 | private MediaPlayer.OnErrorListener onErrorListener = new MediaPlayer.OnErrorListener() { 148 | @Override 149 | public boolean onError(MediaPlayer mp, int what, int extra) { 150 | return true; 151 | } 152 | }; 153 | 154 | //完成监听 155 | private MediaPlayer.OnCompletionListener onCompletionListener = new MediaPlayer.OnCompletionListener() { 156 | @Override 157 | public void onCompletion(MediaPlayer mp) { 158 | //视频播放完成 159 | mediaController.showPlayFinishView(); 160 | } 161 | }; 162 | 163 | //缓冲的监听 164 | private MediaPlayer.OnBufferingUpdateListener onBufferingUpdateListener = new MediaPlayer.OnBufferingUpdateListener() { 165 | @Override 166 | public void onBufferingUpdate(MediaPlayer mp, int percent) { 167 | // Log.i(TAG,"percent:"+percent); 168 | mediaController.updateSeekBarSecondProgress(percent); 169 | } 170 | }; 171 | 172 | 173 | //初始化控件的显示状态 174 | public void initViewDisplay() { 175 | videoView.setVisibility(View.GONE); 176 | mediaController.initViewDisplay(); 177 | } 178 | 179 | //设置视频播放界面的显示 180 | public void setVideoViewVisiable(int visible) { 181 | videoView.setVisibility(View.VISIBLE); 182 | } 183 | 184 | private VideoPlayerItemInfo info; 185 | public void setPlayData(VideoPlayerItemInfo info) { 186 | this.info = info; 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /app/src/main/res/anim/bottom_enter.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/anim/bottom_exit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/biz_video_progress_thumb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackChan1999/VideoPlayer/189c63ab14cea780cd55845ad315f421c4597e4f/app/src/main/res/drawable-hdpi/biz_video_progress_thumb.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/comment_video_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackChan1999/VideoPlayer/189c63ab14cea780cd55845ad315f421c4597e4f/app/src/main/res/drawable-hdpi/comment_video_normal.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/enlarge_fullscreen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackChan1999/VideoPlayer/189c63ab14cea780cd55845ad315f421c4597e4f/app/src/main/res/drawable-hdpi/enlarge_fullscreen.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/more_pgc_comment_normal_night.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackChan1999/VideoPlayer/189c63ab14cea780cd55845ad315f421c4597e4f/app/src/main/res/drawable-hdpi/more_pgc_comment_normal_night.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/new_pause_video.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackChan1999/VideoPlayer/189c63ab14cea780cd55845ad315f421c4597e4f/app/src/main/res/drawable-hdpi/new_pause_video.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/new_play_video.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackChan1999/VideoPlayer/189c63ab14cea780cd55845ad315f421c4597e4f/app/src/main/res/drawable-hdpi/new_play_video.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/qq_allshare_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackChan1999/VideoPlayer/189c63ab14cea780cd55845ad315f421c4597e4f/app/src/main/res/drawable-hdpi/qq_allshare_normal.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/replay_video.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackChan1999/VideoPlayer/189c63ab14cea780cd55845ad315f421c4597e4f/app/src/main/res/drawable-hdpi/replay_video.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/share_video.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackChan1999/VideoPlayer/189c63ab14cea780cd55845ad315f421c4597e4f/app/src/main/res/drawable-hdpi/share_video.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/sb_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/sb_progress.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/sb_progress_drawable.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/sb_second.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/tv_time_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_video_play.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 12 | 19 | 20 | 21 | 26 | 27 | 28 | 29 | 30 | 36 | 37 | 42 | 43 | 50 | 51 | 59 | 60 | 66 | 67 | 74 | 75 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /app/src/main/res/layout/video_controller.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 15 | 16 | 22 | 23 | 28 | 29 | 35 | 36 | 41 | 42 | 50 | 51 | 52 | 57 | 58 | 63 | 64 | 72 | 73 | 74 | 75 | 76 | 85 | 86 | 93 | 94 | 109 | 110 | 120 | 121 | 129 | 130 | 139 | 140 | 148 | 149 | 154 | 155 | -------------------------------------------------------------------------------- /app/src/main/res/layout/video_play.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 13 | 14 | 15 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackChan1999/VideoPlayer/189c63ab14cea780cd55845ad315f421c4597e4f/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackChan1999/VideoPlayer/189c63ab14cea780cd55845ad315f421c4597e4f/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackChan1999/VideoPlayer/189c63ab14cea780cd55845ad315f421c4597e4f/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackChan1999/VideoPlayer/189c63ab14cea780cd55845ad315f421c4597e4f/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/beautiful.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackChan1999/VideoPlayer/189c63ab14cea780cd55845ad315f421c4597e4f/app/src/main/res/mipmap-xhdpi/beautiful.jpg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackChan1999/VideoPlayer/189c63ab14cea780cd55845ad315f421c4597e4f/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackChan1999/VideoPlayer/189c63ab14cea780cd55845ad315f421c4597e4f/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackChan1999/VideoPlayer/189c63ab14cea780cd55845ad315f421c4597e4f/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackChan1999/VideoPlayer/189c63ab14cea780cd55845ad315f421c4597e4f/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackChan1999/VideoPlayer/189c63ab14cea780cd55845ad315f421c4597e4f/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackChan1999/VideoPlayer/189c63ab14cea780cd55845ad315f421c4597e4f/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/color.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | VideoPlayer 3 | 北大美女学霸为音乐放弃保研 成金曲奖最大黑马 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/jackchan/videoplayer/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.jackchan.videoplayer; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /art/VideoMediaController1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackChan1999/VideoPlayer/189c63ab14cea780cd55845ad315f421c4597e4f/art/VideoMediaController1.jpg -------------------------------------------------------------------------------- /art/VideoMediaController2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackChan1999/VideoPlayer/189c63ab14cea780cd55845ad315f421c4597e4f/art/VideoMediaController2.jpg -------------------------------------------------------------------------------- /art/VideoPlayer.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackChan1999/VideoPlayer/189c63ab14cea780cd55845ad315f421c4597e4f/art/VideoPlayer.jpg -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.3.0' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JackChan1999/VideoPlayer/189c63ab14cea780cd55845ad315f421c4597e4f/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed May 24 16:50:35 CST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------