媒體數(shù)據(jù)寫入

2024-01-22 17:36 更新

可用于EGL/OpenGLES和媒體數(shù)據(jù)寫入,并顯示在XComponent組件。

說(shuō)明

該組件從API Version 8 開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨(dú)標(biāo)記該內(nèi)容的起始版本。

子組件

構(gòu)造參數(shù)type為"surface"時(shí)不支持。

從API version 9開始,構(gòu)造參數(shù)type為"component"時(shí)可以包含子組件。

接口

XComponent(value: {id: string, type: string, libraryname?: string, controller?: XComponentController})

參數(shù):

參數(shù)名

參數(shù)類型

必填

描述

id

string

組件的唯一標(biāo)識(shí),支持最大的字符串長(zhǎng)度128。

type

string

用于指定XComponent組件類型,可選值為:

-"surface":用于EGL/OpenGLES和媒體數(shù)據(jù)寫入,組件內(nèi)容單獨(dú)送顯,直接合成到屏幕。

-"component"9+ :XComponent將變成一個(gè)容器組件,并可在其中執(zhí)行非UI邏輯以動(dòng)態(tài)加載顯示內(nèi)容。

libraryname

string

應(yīng)用Native層編譯輸出動(dòng)態(tài)庫(kù)名稱,僅XComponent類型為"surface"時(shí)有效。

controller

XComponentcontroller

給組件綁定一個(gè)控制器,通過(guò)控制器調(diào)用組件方法,僅XComponent類型為"surface"時(shí)有效。

說(shuō)明

type為"component"時(shí),XComponent作為容器,子組件沿垂直方向布局:

  • 垂直方向上對(duì)齊格式:FlexAlign.Start
  • 水平方向上對(duì)齊格式:FlexAlign.Center

所有的事件響應(yīng)均不支持。

布局方式更改和事件響應(yīng)均可通過(guò)掛載子組件來(lái)設(shè)置。

內(nèi)部所寫的非UI邏輯需要封裝在一個(gè)或多個(gè)函數(shù)內(nèi)。

屬性

  • XComponent顯示的內(nèi)容,可由開發(fā)者自定義繪制,通用屬性不支持背景設(shè)置、透明度設(shè)置圖像效果
  • type為"surface"時(shí)建議使用EGL/OpenGLES提供的接口設(shè)置相關(guān)內(nèi)容。
  • type為"component"時(shí)建議使用掛載子組件的方式進(jìn)行設(shè)置相關(guān)內(nèi)容。

事件

僅type為"surface"時(shí)以下事件有效。不支持通用事件手勢(shì)。

onLoad

onLoad(callback: (event?: object) => void )

插件加載完成時(shí)回調(diào)事件。

參數(shù):

參數(shù)名

參數(shù)類型

必填

描述

event

object

獲取XComponent實(shí)例對(duì)象的context,context上掛載的方法由開發(fā)者在c++層定義。

onDestroy

onDestroy(event: () => void )

插件卸載完成時(shí)回調(diào)事件。

XComponentController

xcomponent 組件的控制器,可以將此對(duì)象綁定至XComponent組件,然后通過(guò)控制器來(lái)調(diào)用組件方法。

創(chuàng)建對(duì)象

  1. xcomponentController: XComponentController = new XComponentController()

getXComponentSurfaceId

getXComponentSurfaceId(): string

獲取XComponent對(duì)應(yīng)Surface的ID,供@ohos接口使用,僅XComponent類型為"surface"時(shí)有效。

返回值:

類型

描述

string

XComponent持有Surface的ID。

setXComponentSurfaceSize

setXComponentSurfaceSize(value: {surfaceWidth: number, surfaceHeight: number}): void

設(shè)置XComponent持有Surface的寬度和高度,僅XComponent類型為"surface"時(shí)有效。

參數(shù):

參數(shù)名

參數(shù)類型

必填

描述

surfaceWidth

number

XComponent持有Surface的寬度。

surfaceHeight

number

XComponent持有Surface的高度。

getXComponentContext

getXComponentContext(): Object

獲取XComponent實(shí)例對(duì)象的context,僅XComponent類型為"surface"時(shí)有效。

返回值:

類型

描述

Object

獲取XComponent實(shí)例對(duì)象的context,context包含的具體接口方法由開發(fā)者自定義。

示例

示例效果請(qǐng)以真機(jī)運(yùn)行為準(zhǔn),當(dāng)前IDE預(yù)覽器不支持。

  1. // xxx.ets
  2. @Entry
  3. @Component
  4. struct PreviewArea {
  5. private surfaceId : string =''
  6. xcomponentController: XComponentController = new XComponentController()
  7. build() {
  8. Row() {
  9. XComponent({
  10. id: 'xcomponent',
  11. type: 'surface',
  12. controller: this.xcomponentController
  13. })
  14. .onLoad(() => {
  15. this.xcomponentController.setXComponentSurfaceSize({surfaceWidth:1920,surfaceHeight:1080});
  16. this.surfaceId = this.xcomponentController.getXComponentSurfaceId()
  17. })
  18. .width('640px')
  19. .height('480px')
  20. }
  21. .backgroundColor(Color.Black)
  22. .position({x: 0, y: 48})
  23. }
  24. }
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)