成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

OpenHarmony3.1新特性-surface+videoplayer實現視頻播放

系統 OpenHarmony
千呼萬喚始出來,在OpenHarmony最新發布的3.1版本中終于支持了surface+videoplayer實現視頻播放的功能。

??想了解更多內容,請訪問:??

??51CTO OpenHarmony技術社區??

??https://ost.51cto.com??

千呼萬喚始出來,在OpenHarmony最新發布的3.1版本中終于支持了surface+videoplayer實現視頻播放的功能。

1、 surface+videoplayer視頻播放與傳統的video組件對比

大家可能覺得不是很早就支持一個video組件就可以實現視頻播放嗎?是的,video組件也就簡簡單單能做個視頻播放,而你仔細去查閱下,video組件支持的api功能太少了,很多定制化功能都無法實現。下面是3.1版本上video組件所具備的api:

而在3.1中添加了一個關鍵組件就是xcomponent,它可以設置一個type為surface,而我更關心的就是這個surface,在講surface之前我先講講videoplayer。

3.1版本中同時還新增了視頻播放的媒體服務videoplayer,它為我們提供了視頻播放服務相關的各種api,video組件所具備的功能它全部具備,同時還具備視頻首幀送顯上報事件、監聽視頻播放寬高變化事件、監聽視頻緩存更新事件等等高級功能,這樣就可以幫助我們自定義出非常高級的視頻播放器出來了。

而videoplayer它只是個做視頻播放的媒體服務,它并不能直接項video組件那樣輸出視頻顯示在顯示器上,這個時候就需要借助surface了。Surface可以簡單的理解為繪制時用的畫布,在hml布局文件中添加一個xcomponent組件并設置type為surface,就相當于放置了一塊畫布。而surface在程序中可以抽象為一塊內存,在js代碼中xcomponent組件通過調用getXComponentSurfaceId()方法可以申請這塊內存,然后就可以隨意的繪制,videoplayer在完成視頻的編解碼服務之后,可以通過調用setDisplaySurface這個方法將視頻內容輸出到之前的surface內存中,從而達到最終視頻在窗口上顯示的功能。下圖是基本架構圖

2、 surface+videoplayer視頻播放代碼實現

下面只實現一個最基礎的視頻播放功能。

首先是編寫hml布局文件,代碼如下:

<div class="container">
<xcomponent id="Xcomponent" type='surface' onload='LoadXcomponent'
style="width : 400px; height : 200px; border-color : red; border-width : 5px;"></xcomponent>
</div>

然后編寫js文件,代碼如下:

import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio'
let videoPlayer = undefined;
let surfaceID = undefined; // 用于保存Xcomponent接口返回的surfaceID
export default {
data: {
title: ""
},
onInit() {
},
// 調用Xcomponent的接口用于獲取surfaceID,并保存在surfaceID變量中,該接口由XComponent組件默認加載,非主動調用
async LoadXcomponent() {
surfaceID = this.$element('Xcomponent').getXComponentSurfaceId();
console.info('LoadXcomponent surfaceID is' + surfaceID);
// 用戶選擇視頻設置fd(本地播放)
let fdPath = 'fd://';
// path路徑的碼流可通過"hdc file send D:\xxx\01.mp3 /data/accounts/account_0/appdata" 命令,將其推送到設備上
let path = '/data/accounts/account_0/appdata/1.mp4';
await fileIO.open(path).then(fdNumber => {
fdPath = fdPath + '' + fdNumber;
console.info('open fd sucess fd is' + fdPath);
}, err => {
console.info('open fd failed err is' + err);
});
await media.createVideoPlayer().then((video) => {
if (typeof (video) != 'undefined') {
videoPlayer = video;
console.info('video createVideoPlayer success');
} else {
console.info('video createVideoPlayer fail');
}
}).catch((error) => {
console.info(`video catchCallback, error:${error.message}`);
});
videoPlayer.url = fdPath;
console.info('video url success');
// 設置surfaceID用于顯示視頻畫面
await videoPlayer.setDisplaySurface(surfaceID).then(() => {
console.info('setDisplaySurface success');
}).catch((error) => {
console.info(`video catchCallback, error:${error.message}`);
});
// 調用prepare完成播放前準備工作
await videoPlayer.prepare().then(() => {
console.info('prepare success');
}).catch((error) => {
console.info(`video catchCallback, error:${error.message}`);
});
// 調用play開始播放
await videoPlayer.play().then(() => {
console.info('play success');
}).catch((error) => {
console.info(`video catchCallback, error:${error.message}`);
});
},
}

??想了解更多內容,請訪問:??

??51CTO OpenHarmony技術社區??

??https://ost.51cto.com??

責任編輯:jianghua 來源: 鴻蒙社區
相關推薦

2022-05-07 16:13:59

DevEcoTool鴻蒙

2022-06-01 22:41:29

轉場動畫鴻蒙

2022-07-06 20:40:27

舒爾特方格鴻蒙

2022-07-27 14:30:15

分布式數據鴻蒙

2022-06-28 14:42:26

ETS購物車應用

2022-06-01 22:35:25

滑桿組件鴻蒙

2022-08-16 17:37:06

視頻播放器鴻蒙

2022-11-08 15:48:35

應用開發音樂播放器

2022-04-21 11:55:06

Audio鴻蒙操作系統

2011-11-06 21:19:38

Eclipse

2011-12-16 09:24:53

JavaSpring開源框架

2022-04-11 13:57:38

HarmonyRelease操作系統

2023-05-31 15:45:49

HCS鴻蒙

2022-03-28 15:40:34

harmony鴻蒙操作系統

2022-06-22 09:14:23

事件打點HiSysEvent

2013-10-31 14:56:31

微軟Surface 2

2009-06-04 17:24:29

EJB3.1新特性Time服務

2022-04-14 11:53:38

HarmonyRelease鴻蒙

2023-03-28 09:44:02

開發應用鴻蒙
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 伊人天堂网 | 精品国产欧美 | 亚洲国产精品va在线看黑人 | 日本免费一区二区三区 | 国产精品五月天 | 亚洲看片网站 | 日韩亚洲一区二区 | www.国产日本 | 亚洲精品9999| 国产成人网 | 一级特黄色毛片 | 日日操视频 | 操操日 | 亚洲欧美日韩成人在线 | 日韩二三区| 免费黄色片在线观看 | 黄色大片在线视频 | 婷婷一级片 | 欧美一级高潮片免费的 | 中文字幕一区二区在线观看 | 99爱视频 | 国产一区不卡 | 国产在线网站 | 日韩免费 | 国产乱码精品1区2区3区 | 欧美三区在线观看 | 成人在线视频网站 | 亚洲免费久久久 | 91色在线视频 | 久久久久久国产一区二区三区 | aaaa日韩| 精品伊人久久 | 欧美一区二区三区国产精品 | 97超碰在线播放 | 欧美亚洲免费 | 亚洲午夜网| 黄网站涩免费蜜桃网站 | 国产一区在线免费 | 99久久精品免费看国产免费软件 | 亚洲一区二区三区四区五区午夜 | 91视频进入 |