uniapp 安卓视频播放器原生插件

插件介绍

安卓视频播放器原生插件,支持自定义播放器内核,支持直播拉流,rtmp,rtsp,m38u等流文件播放

插件地址

安卓视频播放器原生插件 - DCloud 插件市场

详细使用文档

 uniapp 安卓视频播放器原生插件使用文档

用法

 在需要使用插件的页面加载以下代码

<leven-videoPlayer ref="refYcVideoPlayer" style="flex:1; height: 300px;" :config="config" @onVideoStatus="onVideoStatus"
    @onVideoProgress="onVideoProgress" @onVideoStatusChanged="onVideoStatusChanged" @onError="onError">
</leven-videoPlayer>

 页面内容

<template>
  <view>
    <uni-card title="安卓视频播放器原生插件">
      <leven-videoPlayer ref="refYcVideoPlayer" style="flex:1; height: 300px;" :config="config" @onVideoStatus="onVideoStatus"
        @onVideoProgress="onVideoProgress" @onVideoStatusChanged="onVideoStatusChanged" @onError="onError">
      </leven-videoPlayer>
      <uni-section title="内核">
        <uni-data-checkbox v-model="config.kernel" :localdata="kernelType"></uni-data-checkbox>
      </uni-section>
      <uni-section title="播放地址">
        <uni-easyinput v-model="config.url" :maxlength="-1" placeholder="请输入播放地址"></uni-easyinput>
      </uni-section>
      <button type="primary" @click="play">开始播放</button>
      <button type="primary" @click="pause">暂停播放</button>
      <button type="primary" @click="resume">继续播放</button>
      <button type="primary" @click="stop">停止播放</button>
      <button type="primary" @click="shotPic">视频截图</button>
      <button type="primary" @click="isPlaying">是否播放中</button>
      <button type="primary" @click="setPlayPosition">设置播放位置</button>
      <button type="primary" @click="fullScreen">全屏播放</button>
      <button type="primary" @click="smallVideo">显示小窗口</button>
      <button type="primary" @click="logStr = ''">清空日志</button>
    </uni-card>
    <uni-card class="uni-card-box" title="日志">
      <view><text style="font-size: 14px; flex-wrap: wrap;">{{logStr}}</text></view>
    </uni-card>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        logStr: "",
        //配置
        config: {
          //播放地址,rtmp://liteavapp.qcloud.com/live/liteavdemoplayerstreamid
          //http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_4x3/gear1/prog_index.m3u8
          //rtsp://rtspstream:effd2f46af6aef62a77b62104ceafbc0@zephyr.rtsp.stream/movie
          url: "http://alvideo.ippzone.com/zyvd/98/90/b753-55fe-11e9-b0d8-00163e0c0248",
          //播放器预览背景图片,支持网络地址
          backgroundImage: "http://www.yeyuboke.com/svga/image_default.jpg",
          //视频标题
          title: "安卓视频播放器原生插件",
          //默认播放内核
          kernel: 1,
          //全屏时是否横屏显示
          fullIsLand: true,
          //是否循环播放
          loop: true,
          //开始播放位置,单位:毫秒
          seekOnStart: 15000
        },
        // 内核
        kernelType: [{
          text: "IJK内核",
          value: 1
        }, {
          text: "EXO内核",
          value: 2
        }, {
          text: "系统内核",
          value: 3
        }],
      }
    },
    methods: {
      // 开始播放
      play() {
        if (this.$refs.refYcVideoPlayer) {
          this.$refs.refYcVideoPlayer.play(this.config, res => {
            this.writeLog("开始播放:" + JSON.stringify(res))
          });
        }
      },
      // 暂停播放
      pause() {
        if (this.$refs.refYcVideoPlayer) {
          this.$refs.refYcVideoPlayer.pause(res => {
            this.writeLog("暂停播放:" + JSON.stringify(res))
          });
        }
      },
      // 继续播放
      resume() {
        if (this.$refs.refYcVideoPlayer) {
          this.$refs.refYcVideoPlayer.resume(res => {
            this.writeLog("继续播放:" + JSON.stringify(res))
          });
        }
      },
      // 停止播放
      stop() {
        if (this.$refs.refYcVideoPlayer) {
          this.$refs.refYcVideoPlayer.stop(res => {
            this.writeLog("停止播放:" + JSON.stringify(res))
          });
        }
      },
      // 视频截图
      shotPic() {
        if (this.$refs.refYcVideoPlayer) {
          this.$refs.refYcVideoPlayer.shotPic(res => {
            this.writeLog("视频截图:" + JSON.stringify(res))
          });
        }
      },
      // 是否播放中
      isPlaying() {
        if (this.$refs.refYcVideoPlayer) {
          this.$refs.refYcVideoPlayer.isPlaying(res => {
            this.writeLog("是否播放中:" + JSON.stringify(res))
          });
        }
      },
      // 设置播放位置
      setPlayPosition() {
        if (this.$refs.refYcVideoPlayer) {
          this.$refs.refYcVideoPlayer.setPlayPosition({
            //播放位置,单位:毫秒
            position: 30000
          }, res => {
            this.writeLog("设置播放位置:" + JSON.stringify(res))
          });
        }
      },
      // 全屏播放
      fullScreen() {
        if (this.$refs.refYcVideoPlayer) {
          this.$refs.refYcVideoPlayer.fullScreen({
            //是否横屏
            isLand: true
          }, res => {
            this.writeLog("全屏播放:" + JSON.stringify(res))
            //10秒后退出全屏
            setTimeout(() => {
              this.$refs.refYcVideoPlayer.quitFullScreen(quitRes => {
                this.writeLog("退出全屏:" + JSON.stringify(quitRes))
              });
            }, 10000)
          });
        }
      },
      // 小窗口播放
      smallVideo() {
        if (this.$refs.refYcVideoPlayer) {
          this.$refs.refYcVideoPlayer.smallVideo({
            //是否横屏
            size: [500, 500]
          }, res => {
            this.writeLog("小窗口播放:" + JSON.stringify(res))

            //10秒后退出小窗口
            setTimeout(() => {
              this.$refs.refYcVideoPlayer.quitSmallVideo(quitRes => {
                this.writeLog("退出小窗口:" + JSON.stringify(quitRes))
              });
            }, 10000)
          });
        }
      },
      //播放状态回调
      onVideoStatus(e) {
        this.writeLog("onVideoStatus:" + JSON.stringify(e.detail))
      },
      //播放进度回调
      onVideoProgress(e) {
        this.writeLog("onVideoProgress:" + JSON.stringify(e.detail))
      },
      //播放状态的变化
      onVideoStatusChanged(e) {
        this.writeLog("onVideoStatusChanged:" + JSON.stringify(e.detail))
      },
      // 系统错误
      onError(e) {
        this.writeLog("onError:" + JSON.stringify(e))
      },
      // 写日志
      writeLog(str) {
        console.log(str);
        let logStr = uni.$lv.date.format(null, "yyyy-mm-dd hh:MM:ss") + " " + str + "\n";
        this.logStr = logStr + this.logStr;
      }
    }
  }
</script>

<style>

</style>

插件方法

  1. 开始播放
  2. 暂停播放
  3. 继续播放
  4. 停止播放
  5. 视频截图
  6. 是否播放中
  7. 设置播放位置
  8. 全屏播放
  9. 退出全屏
  10. 小窗口播放
  11. 关闭小窗口

插件事件

  1.  播放状态回调
  2. 播放进度回调
  3. 播放状态的变化
  4. 系统错误

具体方法的使用请参考使用说明文档 

联系作者

 购买插件前请先试用,试用通过再购买。在试用中如果遇到任何问题,可与作者联系,将全力协助你使用本插件

加入公众号可联系作者

图片预览

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

夜中雨滴

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值