当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
1 Star 0 Fork 38

weijiadev / yjPlay
暂停

forked from Swei / yjPlay
暂停
 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

yjPlay

 

View English instructions→Poking me

gif 显示有点卡,帧数低,实际很流畅

下载预览apk

基于exoPlayer 自定义播放器 JPlayer支持功能:

  • 1 ExoUserPlayer 基本播放
  • 2 GestureVideoPlayer 增加手势 亮度,音量,快进,等手势
  • 3 ManualPlayer 默认手动播放,增加默认图
  • 5 增加广告视频预览切换
  • 6 增加视频清晰度切换
  • 7 增加缓存视频功能
  • 8 支持自定义各种数据源加载 Okttp,Rtmp, 缓存,Cronet等协议,
  • 9 支持列表播放视频
  • 10 支持多种文件类型,MP4,M4A,WebM,Matroska,Ogg,WAV,MP3,MPEG-TS,MPEG-PS,FLV,ADTS (AAC),Flac,M3U8,mkv 等
  • 11 支持网络类型 提示是否播放
  • 12 1.5.5增加,视频加载布局, 错误布局,重播布局,提示布局自定义,更灵活实现自己布局样式
  • 13 支持视频加载中显示模式(网速模式和百分比模式)

更新日志→》戳我查看

查看1.5.7.2升级日志

一.引用类库

 repositories {
        jcenter()
        mavenCentral();
    }

dependencies {
   compile 'com.ycjiang:VideoPlayModule:1.5.7.2'

}

提示:无法正常引用请在 repositories{ }添加已下代码 mavenCentral(url: "https://dl.bintray.com/ycjiang/ycjiang")

二.控件属性

1.控件属性

控件自定义属性

  <chuangyuan.ycj.videolibrary.widget.VideoPlayerView
        android:id="@+id/exo_play_context_id"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"
        app:resize_mode="fit"
        app:show_timeout="3000"
        app:controller_layout_id="@layout/simple_exo_playback_control_view"
        app:player_layout_id="@layout/simple_exo_view"
        app:surface_type="texture_view"
        app:paddingEnd="0dp"
        app:paddingStart="0dp"
        app:fastforward_increment="0"
        app:rewind_increment="0"
        app:user_watermark="@mipmap/watermark_big"
        app:player_list="true"
        app:use_controller="true"
        app:player_replay_layout_id="@layout/custom_play_replay"
        app:player_error_layout_id="@layout/custom_play_error"
        app:player_hint_layout_id="@layout/custom_play_btn_hint"
        app:player_load_layout_id="@layout/custom_exo_play_load"
         />

基本使用如下

      <chuangyuan.ycj.videolibrary.widget.VideoPlayerView
              android:id="@+id/exo_play_context_id"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:background="@android:color/transparent"
              app:controller_layout_id="@layout/simple_exo_playback_control_view"
              app:player_layout_id="@layout/simple_exo_view"
              app:resize_mode="fit"
              app:surface_type="surface_view" />

2.属性说明

  • 必选
1.   player_layout_id  播放器布局, //必选
     player_layout_id 目前支持指定布局simple_exo_playback_control_view 后续版本,开放自定义使用
  • 必选
2. controller_layout_id  控制器布局`  默认有三种布局
    1.simple_exo_playback_control_view.xml  //视频封面控制布局下面,比较常规使用
    2.simple_exo_playback_list_view.xml.xml //在列表播放使用控制布局
    3.simple_exo_playback_top_view.xml.xml  //视频封面控制布局上面
  • 可选 注意: 列表播放只能选择texture_view 不能选择surface_view,详情页面播放推荐surface_view
3.    surface_type 视频渲染类型 //texture_view 和surface_view //枚举类型。默认surface_view
4.   use_controller   是否用户控制控制器  布尔类型
5.   resize_mode  视频缩放渲染显示方式一共4种 //可选  
        1.fit          //正常模式
        2.fixed_width  //保持的是视频宽度,拉伸视频高度
        3.fixed_height //保持的是视频高度,拉伸视频宽度
        4.fill          //全屏模式,拉伸视频宽高
6.   default_artwork  占位图  //可选
7.   show_timeout  控制布局隐藏时间  默认值为3秒  //可选
8.   paddingEnd,paddingStart 设置边距  默认值为0  //可选
9.   fastforward_increment  设置快进增量,以毫秒为单位。 //可选
10.  rewind_increment   设置快退增量,以毫秒为单位。  //可选
11.  user_watermark    水印图片 默认在右上角  //可选
12.  player_list      是否指定列表播放   //可选 默认 false  true 列表播放
13.  player_replay_layout_id  自定义重播布局文件
14.  player_error_layout_id   自定义错误布局文件
15.  player_hint_layout_id   自定义非wifi提示布局文件
16.  player_load_layout_id   自定义视频加载布局文件

3.修改网络对话框提示文字内容

  app.strings.xml
  <string name="exo_play_reminder">您当前网络不是wifi,是否继续观看视频</string>
  <string name="exo_play_wifi_hint_no">提示</string>

4.在功能清单声明 AndroidManifest.xml

在activity节点 加上“android:configChanges="orientation|keyboardHidden|screenSize"”
 如下实例:
        <activity android:name="chuangyuan.ycj.yjplay.MainListActivity"
         android:configChanges="orientation|keyboardHidden|screenSize"
         android:screenOrientation="portrait">

3.JAVA 代码

1 播放控制类

1.ExoUserPlayer 基本播放父类,实现基本播放,设置setPlayUri();会自动加载播放
2.GestureVideoPlayer  具有手势操作播放(调节亮度和视频进度,和音量)会自动加载播放
2.ManualPlayer  点击开始按钮播放,具有手势功能,和列表播放

2 播放代码

     //实例化播放控制类
      ManualPlayer exoPlayerManager = new ManualPlayer(this,R.id.exo_play_context_id);
     //自定义你的数据源,后面详细介绍如何自定义数据源类
      // ManualPlayer exoPlayerManager = new ManualPlayer(this,R.id.exo_play_context_id,new DataSource(this));
      //加载m3u8
      exoPlayerManager.setPlayUri("http://dlhls.cdn.zhanqi.tv/zqlive/35180_KUDhx.m3u8");
      //加载ts.文件
      exoPlayerManager.setPlayUri("http://185.73.239.15:25461/live/1/1/924.ts");
      //播放本地视频
      // exoPlayerManager.setPlayUri("/storage/emulated/0/DCIM/Camera/VID_20170717_011150.mp4");
      //下面开启多线路播放
        exoPlayerManager.setShowVideoSwitch(true); //开启切换按钮,默认关闭
       String [] test={"http://120.25.246.21/vrMobile/travelVideo/zhejiang_xuanchuanpian.mp4","http://120.25.246.21/vrMobile/travelVideo/zhejiang_xuanchuanpian.mp4","http://120.25.246.21/vrMobile/travelVideo/zhejiang_xuanchuanpian.mp4"};
       String[] name={"超清","高清","标清"};
       exoPlayerManager.setPlaySwitchUri(test,name);
      //添加水印图片
      // exoPlayerManager.setExoPlayWatermarkImg();
      //是否屏蔽进度控件拖拽快进视频(例如广告视频,(不允许用户))
       exoPlayerManager.setSeekBarSeek(false);
       //设置视循环播放
       exoPlayerManager.setLooping(10);
       //d隐藏控制布局
       exoPlayerManager.hideControllerView();
        //隐藏进度条
       exoPlayerManager.hideSeekBar();
        //显示进度条
       exoPlayerManager.showSeekBar();
        //是否播放
       exoPlayerManager.isPlaying(); 
       //设置点击播放按钮需要处理业务
       exoPlayerManager.setOnPlayClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View v) {
                          Toast.makeText(MainCustomActivity.this,"定义点击播放事件",Toast.LENGTH_LONG).show();
                           //处理业务操作 完成后,
                           //方法实现setOnPlayClickListener(), 需要手动调用
                           exoPlayerManager.startPlayer();//开始播放
                      }
         }); 

1.实例化播放控制类

      ManualPlayer exoPlayerManager = new ManualPlayer(this,R.id.exo_play_context_id);
      ManualPlayer exoPlayerManager = new ManualPlayer(this,videoPlayerView);

2.自定义你的数据源,后面详细介绍如何自定义数据源类

     ManualPlayer exoPlayerManager = new ManualPlayer(this,R.id.exo_play_context_id,new DataSource(this));
     ManualPlayer exoPlayerManager = new ManualPlayer(this,videoPlayerView,new DataSource(this));

3.设置视频标题

      exoPlayerManager.setTitle("视频标题");

4.添加水印图片

     exoPlayerManager.setExoPlayWatermarkImg(R.mipmap.watermark_big);

5.设置开始播放进度

     exoPlayerManager.setPosition(1000)

6.设置封面图

       videoPlayerView.setPreviewImage(bimtap);或者 videoPlayerView.getPreviewImage())

7.设置视频路径

     exoPlayerManager.setPlayUri("http://dlhls.cdn.zhanqi.tv/zqlive/35180_KUDhx.m3u8");
     exoPlayerManager.setPlayUri(Uri.parse("http://dlhls.cdn.zhanqi.tv/zqlive/35180_KUDhx.m3u8"));
     exoPlayerManager.setPlayUri(Environment.getExternalStorageDirectory().getAbsolutePath()+"/test.h264"); //本地视频

8.设置多线路播放

      //开启多线路设置,默认关闭
      exoPlayerManager.setShowVideoSwitch(true);
      //支持List列表
      String [] test={"http://120.25.246.21/vrMobile/travelVideo/zhejiang_xuanchuanpian.mp4",
      "http://120.25.246.21/vrMobile/travelVideo/zhejiang_xuanchuanpian.mp4",
       http://120.25.246.21/vrMobile/travelVideo/zhejiang_xuanchuanpian.mp4"};
       String[] name={"超清","高清","标清"};
       exoPlayerManager.setPlaySwitchUri(test,name);

9.设置视频加载提示显示模式(默认LoadModelType.SPEED (网速模式))

   /**设置加载百分比显示模式**/
   exoPlayerManager.setLoadModel(LoadModelType.PERCENR);

10.设置监听回调VideoInfoListener

     exoPlayerManager.setVideoInfoListener(new VideoInfoListener() {
                   @Override
                   public void onPlayStart() {
                         //开始播放
                   }

                   @Override
                   public void onLoadingChanged() {
                             //加载变化
                   }

                   @Override
                   public void onPlayerError(ExoPlaybackException e) {
                             //加载错误
                  }

                   @Override
                   public void onPlayEnd() {
                          //播放结束
                   }
                   @Override
                   public void onRepeatModeChanged(int repeatMode) {
                       //模式变化
                   }
               });

11.覆写Activity和Fragment周期方法

            Override
            public void onResume() {
                super.onResume();
                Log.d(TAG, "onResume");
                exoPlayerManager.onResume();
            }

            @Override
            public void onPause() {
                super.onPause();
                Log.d(TAG, "onPause");
                exoPlayerManager.onPause();
            }


            @Override
            protected void onDestroy() {
                exoPlayerManager.onDestroy();
                super.onDestroy();

            }

            @Override
            public void onConfigurationChanged(Configuration newConfig) {
                exoPlayerManager.onConfigurationChanged(newConfig);//横竖屏切换
                super.onConfigurationChanged(newConfig);
            }

            @Override
            public void onBackPressed() {
            //使用播放返回键监听
             if(exoPlayerManager.onBackPressed()){
                 finish();
             }
            }

三.列表

1.列表播放,只能使用ManualPlayer,在你的VideoHolder

  • 1在列表控件使用属性 ”app:controller_layout_id="@layout/simple_exo_playback_list_view"“ //提供默列表控制布局

  • 2.player_list="true" 设置为true 开启列表模式

  • 3.demo: public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.VideoViewHolder> {

         private Context mContext;
         private List<String> mVideoList;
        public VideoAdapter(Context context, List<String> videoList) {
            mContext = context;
            mVideoList = videoList;
        }
    
        @Override
        public int getItemCount() {
            return mVideoList.size();
        }
        @Override
        public VideoViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View itemView = LayoutInflater.from(mContext).inflate(R.layout.item_video1, parent, false);
            return new VideoViewHolder(itemView);
        }
    
        @Override
        public void onBindViewHolder(VideoViewHolder holder, int position) {
            String video = mVideoList.get(position);
            holder.bindData(video);
        }
    
        public class VideoViewHolder extends RecyclerView.ViewHolder {
            ManualPlayer userPlayer;
            VideoPlayerView playerView;
            public VideoViewHolder(View itemView) {
                super(itemView);
                //初始化控件
                playerView = (VideoPlayerView) itemView.findViewById(R.id.item_exo_player_view);
                userPlayer = new ManualPlayer((Activity) mContext, playerView);
            }
    
           /**
           *绑定数据源
           ***/
            public void bindData(String videoBean) {
                userPlayer.setTitle("" + getAdapterPosition());
                userPlayer.setPlayUri(videoBean);
                Glide.with(mContext)
                .load("http://i3.letvimg.com/lc08_yunzhuanma/201707/29/20/49/3280a525bef381311b374579f360e80a_v2_MTMxODYyNjMw/thumb/2_960_540.jpg")
                .into(playerView.getPreviewImage());
            }
        }

2.列表播放周期方法 列表在Activity或者Fragment 实现相应周期方法

                  protected void onPause() {
                      super.onPause();
                      VideoPlayerManager.getInstance().onPause();
                  }
                  @Override
                   protected void onResume() {
                      super.onResume();
                      VideoPlayerManager.getInstance().onResume();
                  }
                  @Override
                  protected void onDestroy() {
                      super.onDestroy();
                      VideoPlayerManager.getInstance().onDestroy();
                  }
                  @Override
                  public void onBackPressed() {
                      //返回监听类
                      if (VideoPlayerManager.getInstance().onBackPressed()){
                          finish();
                      }
                  }

四.数据源工厂类

1.默认数据源

      缓存 : CacheDataSinkFactory,CacheDataSourceFactory
      http : DefaultDataSourceFactory,DefaultHttpDataSourceFactory
      Priority : PriorityDataSourceFactory

2 自定义数据源引用

  compile 'com.google.android.exoplayer:extension-okhttp:r2.5.1'
  compile 'com.google.android.exoplayer:extension-rtmp:r2.5.1'

五.自定义数据源用法-戳我

六.自定义布局用法-戳我

License

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright {yyyy} {name of copyright owner} Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

一个支持自定义布局和直播 手势 亮度,音量,快进,等手势 ,广告视频预览 ,清晰度切换 , 边播放缓存视频, 自定义各种数据源加载,列表播放的播放器 展开 收起
Android
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Android
1
https://gitee.com/weijiadev_admin/yjPlay.git
git@gitee.com:weijiadev_admin/yjPlay.git
weijiadev_admin
yjPlay
yjPlay
master

搜索帮助