android中简单视频播放器demo(附githup下载源码)

android 简单视频播放器demo(免费,赞)

介绍

githup上的下载路径为:https://github.com/wenfujing/video_svg,下载最新的库文件,并且导入到项目的LIB下便可以使用。

该库以及DEMO本地下载链接:下载地址

知识储备

Android-Universal-Image-Loader是一个开源的UI组件程序,该项目的目的是提供一个可重复使用的仪器为异步图像加载,缓存和显示。所以,如果你的程序里需要这个功能的话,那么不妨试试它。因为已经封装好了一些类和方法。我们 可以直接拿来用了。而不用重复去写了。其实,写一个这方面的程序还是比较麻烦的,要考虑多线程,缓存,内存溢出等很多方面。但是,你也可以参考这个例子来自己写出更好的程序。在此为大家介绍一下。效果图如下:

效果图

实现步骤

1、使用
1.1 在project的build.gradle添加如下代码和引入lib库


android {

    compileSdkVersion 29

    buildToolsVersion "29.0.2"

    defaultConfig {

        applicationId "com.ocwvar.video_svg"

        minSdkVersion 19

        targetSdkVersion 29

        versionCode 1

        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

    }

    buildTypes {

        release {

            minifyEnabled false

            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

        }

    }

//依赖(图像异步加载


implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.4'

1.2 运行所需权限

<uses-permission android:name="android.permission.INTERNET"/>

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

1.3 布局文件

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical">

    <fm.jiecao.jcvideoplayer_lib.JCVideoPlayer

        android:id="@+id/jcvideoplayer"

        android:layout_width="match_parent"

        android:layout_height="match_parent" />

</LinearLayout>

1.4 配置清单文件

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="com.ocwvar.video_svg">

    <application

        android:allowBackup="true"

        android:icon="@mipmap/ic_launcher"

        android:label="@string/app_name"

        android:roundIcon="@mipmap/ic_launcher_round"

        android:supportsRtl="true"

        android:theme="@style/AppTheme">

        <activity android:name=".MainActivity"

            android:configChanges="orientation"

            android:screenOrientation="portrait">

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

        <activity

            android:name=".ListActivity"

            android:screenOrientation="portrait" />

        <activity

            android:name=".ListViewpagerActivity"

            android:screenOrientation="portrait" />

        <activity

            android:name=".SetSkinActivity"

            android:screenOrientation="portrait" />

    </application>

</manifest>

1.5 activity 中调运
一行代码调用,大部分需求都能实现,


public class MainActivity extends AppCompatActivity implements View.OnClickListener {

   JCVideoPlayer videoController1, videoController2, videoController3;

   Button btnToList, btnToListViewpager, btnToFullscreen, btnToChangecolor;

   @Override

   protected void onCreate(Bundle savedInstanceState) {

       super.onCreate(savedInstanceState);

       setContentView(R.layout.activity_main);

       /**

       * 如果没有埋点需求,可以不用注册eventbus

       * <br>

       * if you do not want to get Buried Point , you do not need regist eventbus here

       */

       EventBus.getDefault().register(this);

       videoController1 = (JCVideoPlayer) findViewById(R.id.videocontroller1);

       videoController1.setUp("http://2449.vod.myqcloud.com/2449_43b6f696980311e59ed467f22794e792.f20.mp4",
               "http://p.qpic.cn/videoyun/0/2449_43b6f696980311e59ed467f22794e792_1/640",
               "简单代码实现视频播放");
       videoController2 = (JCVideoPlayer) findViewById(R.id.videocontroller2);

       videoController2.setUp("http://2449.vod.myqcloud.com/2449_ded7b566b37911e5942f0b208e48548d.f20.mp4",//
               "http://p.qpic.cn/videoyun/0/2449_ded7b566b37911e5942f0b208e48548d_2/640",
               "简单代码实现视频播放", false);
       videoController3 = (JCVideoPlayer) findViewById(R.id.videocontroller3);

       videoController3.setUp("http://121.40.64.47/resource/mp3/music_yangguang3.mp3",//
               "http://p.qpic.cn/videoyun/0/2449_38e65894d9e211e5b0e0a3699ca1d490_1/640",
               "简单代码实现视频播放");
       btnToList = (Button) findViewById(R.id.to_list_activity);

       btnToListViewpager = (Button) findViewById(R.id.to_list_viewpager_activity);

       btnToFullscreen = (Button) findViewById(R.id.to_fullscreen);

       btnToChangecolor = (Button) findViewById(R.id.to_changecolor_activity);

       btnToList.setOnClickListener(this);

       btnToListViewpager.setOnClickListener(this);

       btnToFullscreen.setOnClickListener(this);

       btnToChangecolor.setOnClickListener(this);

   }

   @Override

   protected void onPause() {

       super.onPause();

       JCVideoPlayer.releaseAllVideos();

   }

   public void onEventMainThread(VideoEvents event) {

       if (event.type == VideoEvents.POINT_START_ICON) {

           Log.i("Video Event", "POINT_START_ICON" + " title is : " + event.obj + " url is : " + event.obj1);

       } else if (event.type == VideoEvents.POINT_START_THUMB) {

           Log.i("Video Event", "POINT_START_THUMB" + " title is : " + event.obj + " url is : " + event.obj1);

       } else if (event.type == VideoEvents.POINT_STOP) {

           Log.i("Video Event", "POINT_STOP" + " title is : " + event.obj + " url is : " + event.obj1);

       } else if (event.type == VideoEvents.POINT_STOP_FULLSCREEN) {

           Log.i("Video Event", "POINT_STOP_FULLSCREEN" + " title is : " + event.obj + " url is : " + event.obj1);

       } else if (event.type == VideoEvents.POINT_RESUME) {

           Log.i("Video Event", "POINT_RESUME" + " title is : " + event.obj + " url is : " + event.obj1);

       } else if (event.type == VideoEvents.POINT_RESUME_FULLSCREEN) {

           Log.i("Video Event", "POINT_RESUME_FULLSCREEN" + " title is : " + event.obj + " url is : " + event.obj1);

       } else if (event.type == VideoEvents.POINT_CLICK_BLANK) {

           Log.i("Video Event", "POINT_CLICK_BLANK" + " title is : " + event.obj + " url is : " + event.obj1);

       } else if (event.type == VideoEvents.POINT_CLICK_BLANK_FULLSCREEN) {

           Log.i("Video Event", "POINT_CLICK_BLANK_FULLSCREEN" + " title is : " + event.obj + " url is : " + event.obj1);

       } else if (event.type == VideoEvents.POINT_CLICK_SEEKBAR) {

           Log.i("Video Event", "POINT_CLICK_SEEKBAR" + " title is : " + event.obj + " url is : " + event.obj1);

       } else if (event.type == VideoEvents.POINT_CLICK_SEEKBAR_FULLSCREEN) {

           Log.i("Video Event", "POINT_CLICK_SEEKBAR_FULLSCREEN" + " title is : " + event.obj + " url is : " + event.obj1);

       } else if (event.type == VideoEvents.POINT_AUTO_COMPLETE) {

           Log.i("Video Event", "POINT_AUTO_COMPLETE" + " title is : " + event.obj + " url is : " + event.obj1);

       } else if (event.type == VideoEvents.POINT_AUTO_COMPLETE_FULLSCREEN) {

           Log.i("Video Event", "POINT_AUTO_COMPLETE_FULLSCREEN" + " title is : " + event.obj + " url is : " + event.obj1);

       } else if (event.type == VideoEvents.POINT_ENTER_FULLSCREEN) {

           Log.i("Video Event", "POINT_ENTER_FULLSCREEN" + " title is : " + event.obj + " url is : " + event.obj1);

       } else if (event.type == VideoEvents.POINT_QUIT_FULLSCREEN) {

           Log.i("Video Event", "POINT_QUIT_FULLSCREEN" + " title is : " + event.obj + " url is : " + event.obj1);

       }

   }

   @Override

   public void onClick(View v) {

       switch (v.getId()) {

           case R.id.to_list_activity:

               startActivity(new Intent(MainActivity.this, ListActivity.class));

               break;

           case R.id.to_list_viewpager_activity:

               startActivity(new Intent(MainActivity.this, ListViewpagerActivity.class));

               break;

           case R.id.to_fullscreen://进入全屏播放

               JCVideoPlayer.toFullscreenActivity(this,

                       "http://2449.vod.myqcloud.com/2449_43b6f696980311e59ed467f22794e792.f20.mp4",

                       "http://p.qpic.cn/videoyun/0/2449_43b6f696980311e59ed467f22794e792_1/640",

                       "简单代码实现视频播放");

               break;

           case R.id.to_changecolor_activity:

               startActivity(new Intent(this, SetSkinActivity.class));

               break;

       }

   }

   @Override

   protected void onDestroy() {

       super.onDestroy();

       EventBus.getDefault().unregister(this);

   }

}

参照项目:https://github.com/qiushi123/VideoDemoQcl

来源:渭水河畔_wenfujing

如何插入一段漂亮的代码片

博客设置页面,选择一款你喜欢的代码片高亮样式,下面展示同样高亮的 代码片.

// An highlighted block
var foo = 'bar';
发布了5 篇原创文章 · 获赞 8 · 访问量 171

猜你喜欢

转载自blog.csdn.net/qq_44761063/article/details/104020357