HarmonyOS 鸿蒙Next 测试vidioPlayer时报错 does not meet UI component syntax 请支援

HarmonyOS 鸿蒙Next 测试vidioPlayer时报错 does not meet UI component syntax 请支援 我正按官方指导流程测试vidioPlayer, 但在调用类的videoPlayerDemo方法报错:

'this.vdPlayer.videoPlayerDemo();' does not meet UI component syntax.

才用DevEco Studio工具不久,编码调试也不熟,现在不知如何解决,卡住了,请看到的来支援一下。

官方指导网址: https://developer.harmonyos.com/cn/docs/documentation/doc-guides/video-playback-0000001281200970
import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio'
class VideoPlayerDemo {
  // 函数调用发生错误时用于上报错误信息
  failureCallback(error) {
    console.info(`error happened,error Name is ${error.name}`);
    console.info(`error happened,error Code is ${error.code}`);
    console.info(`error happened,error Message is ${error.message}`);
  }
  // 当函数调用发生异常时用于上报错误信息
  catchCallback(error) {
    console.info(`catch error happened,error Name is ${error.name}`);
    console.info(`catch error happened,error Code is ${error.code}`);
    console.info(`catch error happened,error Message is ${error.message}`);
  }
  // 用于打印视频轨道信息
  printfDescription(obj) {
    for (let item in obj) {
      let property = obj[item];
      console.info('key is ' + item);
      console.info('value is ' + property);
    }
  }
  async videoPlayerDemo() {
    let videoPlayer = undefined;
    let surfaceID = 'test' // surfaceID用于播放画面显示,具体的值需要通过Xcomponent接口获取,相关文档链接:
    let fdPath = 'fd://'
    // path路径的码流可通过"hdc file send D:\xxx\H264_AAC.mp4 /data/app/el1/bundle/public/ohos.acts.multimedia.video.videoplayer/ohos.acts.multimedia.video.videoplayer/assets/entry/resources/rawfile"
    let path = '/data/app/el1/bundle/public/ohos.acts.multimedia.video.videoplayer/ohos.acts.multimedia.video.videoplayer/assets/entry/resources/rawfile/H264_AAC.mp4';
    await fileIO.open(path).then((fdNumber) => {
      fdPath = fdPath + '' + fdNumber;
      console.info('open fd success fd is' + fdPath);
    }, (err) => {
      console.info('open fd failed err is' + err);
    }).catch((err) => {
      console.info('open fd failed err is' + err);
    });
    // 调用createVideoPlayer接口返回videoPlayer实例对象
    await media.createVideoPlayer().then((video) => {
      if (typeof (video) != 'undefined') {
        console.info('createVideoPlayer success!');
        videoPlayer = video;
      } else {
        console.info('createVideoPlayer fail!');
      }
    }, this.failureCallback).catch(this.catchCallback);
    // 设置播放源
    videoPlayer.url = fdPath;
    // 设置surfaceID用于显示视频画面
    await videoPlayer.setDisplaySurface(surfaceID).then(() => {
      console.info('setDisplaySurface success');
    }, this.failureCallback).catch(this.catchCallback);
    // 调用prepare完成播放前准备工作
    await videoPlayer.prepare().then(() => {
      console.info('prepare success');
    }, this.failureCallback).catch(this.catchCallback);
    // 调用play接口正式开始播放
    await videoPlayer.play().then(() => {
      console.info('play success');
    }, this.failureCallback).catch(this.catchCallback);
    // 结束播放
    await videoPlayer.stop().then(() => {
      console.info('stop success');
    }, this.failureCallback).catch(this.catchCallback);
    // 释放播放资源
    await videoPlayer.release().then(() => {
      console.info('release success');
    }, this.failureCallback).catch(this.catchCallback);
    // 相关对象置undefined
    videoPlayer = undefined;
    surfaceID = undefined;
  }
}
@Entry
@Component
struct Index {
  @State message: string = 'Hello World'
  vdPlayer: VideoPlayerDemo = new VideoPlayerDemo()
  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
      }
      .width('100%')
      this.vdPlayer.videoPlayerDemo();
    }
    .height('100%')
  }
}

更多关于HarmonyOS 鸿蒙Next 测试vidioPlayer时报错 does not meet UI component syntax 请支援的实战教程也可以访问 https://www.itying.com/category-93-b0.html

6 回复

加个这样的响应事件呢?可以吗

更多关于HarmonyOS 鸿蒙Next 测试vidioPlayer时报错 does not meet UI component syntax 请支援的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


谢谢,没有报错。这是一个可用的办法。

我想在HELLO界面上测试播放一个视频,用 官网提供的VideoPlayerDemo类实现,那位大神提供下实现?

这个不属于UI规范吧,build()里面都是些前端ui组件啥的,你去掉试试!

还是没解决问题。我的问题在于官网提供的VideoPlayerDemo类的方法怎么在正常使用不报错,让hello界面上播放视频。

针对您提到的HarmonyOS(鸿蒙)在测试videoPlayer时报错“does not meet UI component syntax”的问题,这通常意味着在定义或使用videoPlayer组件时,其语法或结构不符合鸿蒙系统的UI组件规范。

可能的错误原因包括:

  1. 组件标签错误:检查videoPlayer组件的标签是否正确,确保没有拼写错误。

  2. 属性格式问题:videoPlayer组件的属性设置可能不正确,如属性值类型不匹配、属性名拼写错误等。

  3. 嵌套结构错误:videoPlayer组件可能被错误地嵌套在其他不允许的组件内,或者其内部嵌套了不允许的子组件。

  4. 缺少必要属性:videoPlayer组件可能缺少某些必要的属性,导致系统无法正确解析。

解决步骤:

  • 仔细检查videoPlayer组件的定义,确保其标签、属性和嵌套结构符合鸿蒙系统的UI组件规范。
  • 参考鸿蒙系统的官方文档,确认videoPlayer组件的正确用法和属性设置。
  • 如果错误依旧存在,尝试简化videoPlayer组件的定义,逐步排查问题所在。

如果问题依旧没法解决请联系官网客服,官网地址是 https://www.itying.com/category-93-b0.html

回到顶部