Giter Club home page Giter Club logo

pldroidplayer's Introduction

PLDroidPlayer

PLDroidPlayer 是一个适用于 Android 的音视频播放器 SDK,可高度定制化和二次开发,特色是支持 RTMP 和 HLS 直播流媒体、以及常见音视频文件(如 MP4、M4A )播放。

功能特性

  • 基于 ijkplayer ( based on ffplay )
  • Android Min API 9
  • 支持 RTMP, HLS 协议
  • 支持 ARM, ARM v7a, ARM64 v8a, x86
  • 支持 MediaCodec 硬解码
  • 支持纯音频播放,并支持后台运行
  • 提供 VideoView 控件
  • 可定制化的 MediaController
  • 支持 seekTo()
  • 支持获取当前播放时长 getDuration()
  • 支持获取当前播放的位置 getCurrentPosition()
  • 支持音量控制 setVolume()
  • 提供如下接口:
    • OnPreparedListener
    • OnCompletionListener
    • OnErrorListener
    • OnInfoListener

内容摘要

播放器对比

- ijkplayer PLDroidPlayer
Shared Library Size 较大 较小
Shared Library Count 5个 1个
Widget 有商业授权风险 无商业授权风险
MediaController 难以定制化 容易定制化

使用方法

项目配置

releases/ 目录获取:

  • pldroid-player-xxx.jar
  • ijkmediaplayer-xxx.jar
  • armeabi-v7a/libpldroidplayer.so
  • arm64-v8a/libpldroidplayer.so
  • armeabi/libpldroidplayer.so
  • x86/libpldroidplayer.so

并在项目中加入对应的 jar/so 文件的依赖关系。可参考 PLDroidPlayerDemo 中的做法。

示例代码

Video 播放

1 初始化 VideoView 及其布局

<com.pili.pldroid.player.widget.VideoView
    android:id="@+id/video_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center" />
  mVideoView = (VideoView) findViewById(R.id.video_view);

2 VideoView 与 MediaController 建立联系

  mMediaController.setMediaPlayer(mVideoView);
  mVideoView.setMediaController(mMediaController);

3 传入播放地址,可以是 /path/to/local.mp4 本地文件绝对路径,或 HLS URL,或 RTMP URL

  mVideoView.setVideoPath(mVideoPath);

4 设置 Listener

public class VideoPlayerActivity extends Activity implements
        OnCompletionListener,
        OnInfoListener,
        OnErrorListener,
        OnPreparedListener {
...
  mVideoView.setOnErrorListener(this);
  mVideoView.setOnCompletionListener(this);
  mVideoView.setOnInfoListener(this);
  mVideoView.setOnPreparedListener(this);
...

@Override
public void onCompletion(IMediaPlayer mp) {
  ...
}

@Override
public boolean onError(IMediaPlayer mp, int what, int extra) {
  ...
}

@Override
public boolean onInfo(IMediaPlayer mp, int what, int extra) {
  ...
}

@Override
public void onPrepared(IMediaPlayer mp) {
  ...
}

5 设置 AVOptions

AVOptions options = new AVOptions();
options.setInteger(AVOptions.KEY_GET_AV_FRAME_TIMEOUT, 3 * 1000);         // the unit of timeout is ms
options.setInteger(AVOptions.KEY_MEDIACODEC, 1);                          // 1 -> enable, 0 -> disable
options.setString(AVOptions.KEY_FFLAGS, AVOptions.VALUE_FFLAGS_NOBUFFER); // "nobuffer"
options.setInteger(AVOptions.KEY_BUFFER_TIME, 1000);                      // the unit of buffer time is ms
mVideoView.setAVOptions(options);

AVOptions.KEY_FFLAGS , AVOptions.KEY_BUFFER_TIME 仅对 RTMP 有效;AVOptions 需要在 start()/setVideoPath() 前设置

纯音频播放

1 实例化 AudioPlayer

mAudioPlayer = new AudioPlayer(this);

2 AudioPlayerMediaController 建立联系

mMediaController.setMediaPlayer(mAudioPlayer);
mAudioPlayer.setMediaController(mMediaController);

3 传入播放地址,可以是 /path/to/local.mp3 本地音频文件绝对路径,或 HLS URL,或 RTMP URL

mAudioPlayer.setAudioPath(mAudioPath);

4 设置 Listener

mAudioPlayer.setOnErrorListener(this);
mAudioPlayer.setOnCompletionListener(this);
mAudioPlayer.setOnInfoListener(this);
mAudioPlayer.setOnPreparedListener(this);

依赖库

  • ffmpeg
  • libyuv
  • sdl
  • libVLC

版本历史

播放器

  • 1.1.3 (Release Notes)

    • 发布 pldroid-player-1.1.3.jar
    • 更新 libpldroidplayer.so
    • 新增 armeabi, x86 支持
    • 新增 KEY_LIVE_STREAMING option
    • 修复 getCurrentPositiongetDuration 返回值异常问题
    • 修复播放过程中,概率性不间断地回调 onCompletion 问题
    • 更新不同播放方式(直播或点播)设置 option 的展示代码
  • 1.1.2 (Release Notes)

    • 发布 pldroid-player-1.1.2.jar
    • 更新 arm64-v8a/libpldroidplayer.so,armeabi-v7a/libpldroidplayer.so
    • 修复推流端断流后,Player 概率性地无 onCompletion 回调通知
    • 修复 AVOptions 的 key 没有设置 value 时候的 Crash 问题
  • 1.1.1 (Release Notes)

    • 发布 pldroid-player-1.1.1.jar
    • 发布 arm64-v8a/libpldroidplayer.so,增加 arm64 v8a 支持
    • 更新 arm-v7a 版本的 libpldroidplayer.so
    • 增加 AVOptions 类,可设置如下属性:
      • AVOptions.KEY_GET_AV_FRAME_TIMEOUT // ms
      • AVOptions.KEY_MEDIACODEC // 1 means enable, 0 means disable
      • AVOptions.KEY_FFLAGS // "nobuffer"
      • AVOptions.KEY_BUFFER_TIME // ms
    • 修复部分音视频流无法播放的问题
    • 修复仅含视频流无法播放的问题
    • 优化连接时间
    • 废除 setBufferTime(float ms) 接口,使用 AVOptions 代替
    • 增加 AVOptions 的演示代码
  • 1.1.0 (Release Notes)

    • 发布 pldroid-player-1.1.0.jar
    • 更新 ijkmediaplayer.jar
    • 更新 libpldroidplayer.so
    • 添加纯音频播放接口,支持后台运行
    • 添加 bufferTime 设置接口:setBufferTime(float ms)
    • 添加状态码:EXTRA_CODE_CONNECTION_REFUSEDEXTRA_CODE_EOF
    • 优化播放延时
    • 优化播放过程中因断流导致的等待时间
    • 修复部分机型硬解码异常问题
    • 添加纯音频播放展示界面
  • 1.0.0 (Release Notes)

    • 发布 PLDroidPlayer v1.0.0

pldroidplayer's People

Contributors

jpxiong avatar why404 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.