基于鸿蒙API10的RTSP播放器(二:视频切换实现)

目标:

  1. 设置一个播放下一个视频的按钮,通过改变url地址实现 ✔
  2. 设置一个视频播放底部轨道,轨道左侧固定为00:00,右侧为当前已经播放的时长差✖
  3. 设置音量调节按钮,再实现滑动增减音量发✖
ts 复制代码
// 这里为ArkTS代码,标记为ts只是为了上色好看。注意代码放置位置

// 1.播放位置状态变量,在结构体之外
let  locationIndex:number = 0 ;

// 2.设置url组,苹果测试地址,最快  

@State private playerURL: string = "http://devimages.apple.com/iphone/samples/bipbop/gear3/prog_index.m3u8";  
  
@State private playerURLs:string[] = [  
  // 苹果测试地址,3s  
  "http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8",  
  // 苹果测试地址,1s  
 'http://devimages.apple.com/iphone/samples/bipbop/gear3/prog_index.m3u8',  
  // 苹果测试,4s  
  "http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_4x3/bipbop_4x3_variant.m3u8",  
  // BBC测试  
  "https://vs-dash-ww-rd-live.akamaized.net/pl/testcard2020/avc-mobile.m3u8",  
  // 苹果测试  
  "http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_4x3/bipbop_4x3_variant.m3u8",  
  // 远程湖面监控  
  "rtsp://stream.strba.sk:1935/strba/VYHLAD_JAZERO.stream",  
  // BBC测试  
  "https://vs-dash-ww-rd-live.akamaized.net/pl/testcard2020/avc-mobile.m3u8",  
  // 海边沙滩监控  
  "rtsp://37.157.51.30/axis-media/media.amp",  
  // BBC测试  
  "https://vs-dash-ww-rd-live.akamaized.net/pl/testcard2020/avc-mobile.m3u8",  
  // 灯光闪烁监控  
  // "rtsp://77.110.228.219/axis-media/media.amp",  
  // BBC测试  
  "https://vs-dash-ww-rd-live.akamaized.net/pl/testcard2020/avc-mobile.m3u8",  
  // 观测站监控  
  "rtsp://196.21.92.82/axis-media/media.amp",  
]

//3.设置改变位置变量函数,通过改变url地址播放下一个视频  
nextPlayer() {  
  // 循环条件  
  if (locationIndex == this.playerURLs.length - 1) {  
    locationIndex = 0;  
  } else {  
    locationIndex++;  
  }  
  // 停止播放  
  mIjkMediaPlayer.stop();  
  mIjkMediaPlayer.reset();  
  this.playerURL = this.playerURLs[locationIndex]  
  this.play(this.playerURL);  
}

//4.在build()函数中通过按钮调用nextPlayer()方法
Button('Next')  
  .width('200px')  
  .onClick(() => {  
    this.nextPlayer();  
  })
相关推荐
小白郭莫搞科技3 小时前
鸿蒙跨端框架Flutter学习:CustomTween自定义Tween详解
学习·flutter·harmonyos
mocoding3 小时前
使用鸿蒙化flutter_fluttertoast替换Flutter原有的SnackBar提示弹窗
flutter·华为·harmonyos
2601_949593657 小时前
高级进阶React Native 鸿蒙跨平台开发:LinearGradient 背景渐变与主题切换
react native·react.js·harmonyos
深海呐7 小时前
鸿蒙基本UI控件(List相关-含Grid)
harmonyos·harmonyos ui·harmonyos list·harmonyos grid·鸿蒙列表view·art列表ui控件·art网格ui控件
小雨青年7 小时前
鸿蒙 HarmonyOS 6 | AI Kit 集成 Core Speech Kit 语音服务
人工智能·华为·harmonyos
一起养小猫8 小时前
Flutter for OpenHarmony 实战 表单处理与验证完整指南
android·开发语言·前端·javascript·flutter·harmonyos
EasyCVR9 小时前
国标GB28181视频监控平台EasyCVR智慧农场监管可视化方案设计
音视频
摘星编程9 小时前
React Native鸿蒙版:自定义useMask输入掩码
react native·react.js·harmonyos
mocoding9 小时前
使用Flutter设置UI三方库card_settings_ui重构鸿蒙版天气预报我的页面
flutter·ui·harmonyos
摘星编程9 小时前
OpenHarmony + RN:自定义useValidator表单验证
react native·react.js·harmonyos