欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

鴻蒙HarmonyOS視頻播放的實(shí)現(xiàn)

 更新時(shí)間:2020年09月14日 09:08:35   作者:鴻蒙技術(shù)社區(qū)  
這篇文章主要介紹了鴻蒙HarmonyOS視頻播放的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

一、介紹

本篇Codelab將實(shí)現(xiàn)的內(nèi)容
HarmonyOS是面向全場(chǎng)景多終端的分布式操作系統(tǒng),使得應(yīng)用程序的開(kāi)發(fā)打破了智能終端互通的性能和數(shù)據(jù)壁壘,業(yè)務(wù)邏輯原子化開(kāi)發(fā),適配多端。通過(guò)一個(gè)簡(jiǎn)單應(yīng)用開(kāi)發(fā),體驗(yàn)HarmonyOS的視頻播放能力

您將建立什么
在這個(gè)Codelab中,你將創(chuàng)建Demo Project,并將Demo編譯成Hap,此示例應(yīng)用程序展示了如何播放視頻。

您將會(huì)學(xué)到什么

如何創(chuàng)建一個(gè)HarmonyOS Demo Project如何構(gòu)建一個(gè)Hap并且將其部署到智慧屏真機(jī)通過(guò)此示例應(yīng)用體驗(yàn)如何播放本地或者在線(xiàn)視頻

二、您需要什么

 1. 硬件要求

  • 操作系統(tǒng):Windows10 64位
  • 內(nèi)存:8G及以上。
  • 硬盤(pán):100G及以上。
  • 分辨率:1280*800及以上

2. 軟件要求

  • 需手動(dòng)下載安裝,詳細(xì)步驟請(qǐng)參考《DevEco Studio使用指南》2.1.2
  • JDK:DevEco Studio自動(dòng)安裝。
  • Node.js:請(qǐng)手動(dòng)下載安裝,詳細(xì)步驟請(qǐng)參考《DevEco Studio使用指南》2.1.3 下載和安裝Node.js。
  • HarmonyOS SDK:待DevEco Studio安裝完成后,利用DevEco Studio來(lái)加載HarmonyOS SDK。詳細(xì)步驟請(qǐng)參考《DevEco Studio使用指南》2.1.6 加載HarmonyOS SDK。
  • Maven庫(kù)依賴(lài)包:如需手動(dòng)拷貝和配置,詳細(xì)步驟請(qǐng)參考《DevEco Studio使用指南》2.3 離線(xiàn)方式配置Maven庫(kù)。

3. 需要的知識(shí)點(diǎn)

Java基礎(chǔ)開(kāi)發(fā)能力。

三、能力接入準(zhǔn)備

實(shí)現(xiàn)HarmonyOS應(yīng)用開(kāi)發(fā),需要完成以下準(zhǔn)備工作:

1.環(huán)境準(zhǔn)備。
2.環(huán)境搭建。
3.創(chuàng)建項(xiàng)目
4.申請(qǐng)調(diào)試證書(shū)
5.應(yīng)用開(kāi)發(fā)

具體操作,請(qǐng)按照《DevEco Studio使用指南》中詳細(xì)說(shuō)明來(lái)完成。
提示:需要通過(guò)注冊(cè)成開(kāi)發(fā)者才能完成集成準(zhǔn)備中的操作。

四、代碼片段

1. 布局:

創(chuàng)建播放視頻的Ability

public class VedioPlayAbilitySlice extends AbilitySlice implements SurfaceOps.Callback

布局截圖:

布局代碼:

//設(shè)置頁(yè)面背景透明
WindowManager windowManager = WindowManager.getInstance();
Window window = windowManager.getTopWindow().get();
window.setTransparent(true);

//頁(yè)面父布局 
DependentLayout myLayout = new DependentLayout(this);
DependentLayout.LayoutConfig params = new DependentLayout.LayoutConfig(MATCH_PARENT, MATCH_PARENT);
myLayout.setLayoutConfig(params);
//顯示視頻的自定義videoView
DependentLayout.LayoutConfig lpVideo = new DependentLayout.LayoutConfig(MATCH_PARENT, MATCH_PARENT);
videoView = new VideoView(this, this);
videoView.setHandler(handler);
myLayout.addComponent(videoView, lpVideo);

DependentLayout rlParent = new DependentLayout(this);
DependentLayout.LayoutConfig lpParent = new DependentLayout.LayoutConfig(MATCH_PARENT, WRAP_CONTENT);
lpParent.addRule(DependentLayout.ALIGN_PARENT_BOTTOM);
lpParent.leftMargin = ConvertUtils.dp2Px(40);
lpParent.rightMargin = ConvertUtils.dp2Px(40);
lpParent.bottomMargin = ConvertUtils.dp2Px(40);
myLayout.addComponent(rlParent, lpParent);
//顯示播放暫停按鈕
playBtn = new Image(this);
DependentLayout.LayoutConfig lpPlayBtn = new DependentLayout.LayoutConfig(ConvertUtils.dp2Px(40), ConvertUtils.dp2Px(40));
lpPlayBtn.addRule(DependentLayout.ALIGN_PARENT_RIGHT);
playBtn.setLayoutConfig(lpPlayBtn);
playBtn.setId(1112);
playBtn.setPixelMap(ResourceTable.Media_pause);
playBtn.setScaleType(Image.ScaleType.SCALE_TO_FULL);
playBtn.invalidate();
playBtn.setClickedListener(new Component.ClickedListener() {
@Override
public void onClick(Component component) {
  if (videoView.getPlayState() == VideoView.STATE_PLAYING) {
    videoView.pause();
    playBtn.setPixelMap(ResourceTable.Media_play);
  } else {
    videoView.start();
    playBtn.setPixelMap(ResourceTable.Media_pause);
  }
}
});
rlParent.addComponent(playBtn);
//顯示當(dāng)前視頻播放時(shí)間
timePlay = new Text(this);
DependentLayout.LayoutConfig lpTimePlay = new DependentLayout.LayoutConfig(WRAP_CONTENT, WRAP_CONTENT);
lpTimePlay.addRule(DependentLayout.CENTER_VERTICAL);
timePlay.setLayoutConfig(lpTimePlay);
timePlay.setId(1111);
timePlay.setText("00:00/00:00");
timePlay.setTextSize(40);
timePlay.setTextColor(Color.WHITE);
rlParent.addComponent(timePlay);
// 顯示播放進(jìn)度條
roundProgressBar = new ProgressBar(this);
roundProgressBar.setProgressWidth(ConvertUtils.dp2Px(5));
roundProgressBar.setProgressColor(Color.RED);
roundProgressBar.setMax(100);
roundProgressBar.setProgress(0);
DependentLayout.LayoutConfig lpProgressBar = new DependentLayout.LayoutConfig(MATCH_PARENT, ConvertUtils.dp2Px(40));
lpProgressBar.addRule(DependentLayout.RIGHT_OF, timePlay.getId());
lpProgressBar.leftMargin = ConvertUtils.dp2Px(20);
lpProgressBar.rightMargin = ConvertUtils.dp2Px(60);
rlParent.addComponent(roundProgressBar, lpProgressBar);

2. 自定義VideoView

繼承父類(lèi)SurfaceProvider:

public class VideoView extends SurfaceProvider implements Player.IPlayerCallback

初始化:

public VideoView(Context context, SurfaceOps.Callback callback) {
super(context);
player = new Player(getContext());
player.setPlayerCallback(this);
Optional<SurfaceOps> surfaceHolderOptional = getSurfaceOps();
SurfaceOps surfaceHolder = surfaceHolderOptional.get();
surfaceHolder.addCallback(callback);
setZOrderOnTop(false);
state = STATE_INIT;
}

播放視頻
如果播放的是在線(xiàn)視頻,需要申請(qǐng)網(wǎng)絡(luò)權(quán)限:

"reqPermissions": [
 {
  "name": "harmonyos.permission.INTERNET"
 }
]


public void playAssets(String fileName, boolean isLooping, SurfaceOps holder) {
  try {
//播放本地視頻:    //player.setSource(getContext().getResourceManager().getRawFileEntry(fileName).openRawFileDescriptor());
//播放在線(xiàn)視頻:
    player.setSource(new Source("https://media.w3.org/2010/05/sintel/trailer.mp4"));
    player.setVideoSurface(holder.getSurface());
    player.enableSingleLooping(isLooping);
    player.enableScreenOn(true);
    player.prepare();
    initPlayViewSize();
    player.play();
    if (state != STATE_INIT) {
      player.rewindTo(currentTime * 1000);
    }
    state = STATE_PLAYING;
    handler.sendEvent(InnerEvent.get(MESSAGE_UPDATE_PLAY_TIME));
  } catch (Exception e) {
    e.printStackTrace();
    Log.hiLog(e.toString());
  }
}

private void initPlayViewSize() {
  int videoWidth = player.getVideoWidth();
  int videoHeight = player.getVideoHeight();
  Log.hiLog("videoWidth:" + videoWidth + ", videoHeight:" + videoHeight);
  if (videoWidth < videoHeight) {
    double scale = screenHeight * 1.f / videoHeight;
    double currHeight = videoHeight * scale;
    double currWidth = videoWidth * scale;
    setHeight(((int) currHeight));
    setWidth(((int) currWidth));
  } else {
    double scale = screenWidth * 1.f / videoWidth;
    double currHeight = videoHeight * scale;
    double currWidth = videoWidth * scale;
    setHeight(((int) currHeight));
    setWidth(((int) currWidth));
  }
}

暫停:

public void pause() {
if (state == STATE_PLAYING) {
  player.pause();
  state = STATE_PAUSE;
}
}

在AbilitySlice啟動(dòng)自動(dòng)播放:

@Override
public void surfaceCreated(SurfaceOps surfaceOps) {
Log.hiLog("surfaceCreated");
videoView.playAssets("resources/rawfile/VID_20200613_204240.mp4", true, surfaceOps);
}

@Override
public void surfaceDestroyed(SurfaceOps surfaceOps) {
Log.hiLog("surfaceDestroyed");
videoView.stop();
}

3. 響應(yīng)遙控器點(diǎn)擊

@Override
public boolean onKeyUp(int keyCode, KeyEvent keyEvent) {
  switch (keyCode) {
    case KeyEvent.KEY_DPAD_CENTER:
    case KeyEvent.KEY_ENTER:
      playBtn.performClick();
      return true;
    default:
        break;
  }
  return false;
}

4. 編譯運(yùn)行該應(yīng)用

通過(guò)hdc連接大屏設(shè)備
先查看智慧屏IP:

大屏設(shè)置->"網(wǎng)絡(luò)與連接"->"網(wǎng)絡(luò)"->"有線(xiàn)網(wǎng)絡(luò)"

在cmd或者IDE的Terminal輸入命令:

hdc tconn 192.168.3.9:5555

運(yùn)行hap

五、恭喜你

干得好,你已經(jīng)成功完成了HarmonyOS應(yīng)用開(kāi)發(fā)E2E體驗(yàn),學(xué)到了:

1.如何創(chuàng)建一個(gè)HarmonyOS Demo Project
2.如何構(gòu)建一個(gè)Hap并且將其部署到真機(jī)
3.在HarmonyOS上如何使用HarmonyOS的視頻播放的能力

到此這篇關(guān)于鴻蒙HarmonyOS視頻播放的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)HarmonyOS視頻播放內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • windows 通過(guò)端口殺死進(jìn)程過(guò)程解析(bat)

    windows 通過(guò)端口殺死進(jìn)程過(guò)程解析(bat)

    這篇文章主要介紹了windows 通過(guò)端口殺死進(jìn)程過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-10-10
  • window下關(guān)閉占用端口使用方法詳解

    window下關(guān)閉占用端口使用方法詳解

    這篇文章主要介紹了window下關(guān)閉占用端口使用方法詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-09-09
  • 詳解uboot各目錄下的文件作用

    詳解uboot各目錄下的文件作用

    這篇文章主要介紹了詳解uboot各目錄下的文件作用的相關(guān)資料,需要的朋友可以參考下
    2017-04-04
  • Windows Docker 安裝 Gitlab Volume權(quán)限問(wèn)題解決方案

    Windows Docker 安裝 Gitlab Volume權(quán)限問(wèn)題解決方案

    這篇文章主要介紹了Windows Docker 安裝 Gitlab Volume權(quán)限問(wèn)題解決方案,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-09-09
  • Windows服務(wù)器修改遠(yuǎn)程桌面默認(rèn)端口過(guò)程圖示

    Windows服務(wù)器修改遠(yuǎn)程桌面默認(rèn)端口過(guò)程圖示

    這篇文章主要介紹了Windows服務(wù)器修改遠(yuǎn)程桌面默認(rèn)端口過(guò)程圖示,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-11-11
  • win10設(shè)定計(jì)劃任務(wù)時(shí)提示所指定的賬戶(hù)名稱(chēng)無(wú)效問(wèn)題解析

    win10設(shè)定計(jì)劃任務(wù)時(shí)提示所指定的賬戶(hù)名稱(chēng)無(wú)效問(wèn)題解析

    這篇文章主要介紹了win10設(shè)定計(jì)劃任務(wù)時(shí)提示所指定的賬戶(hù)名稱(chēng)無(wú)效問(wèn)題解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-09-09
  • 鴻蒙HarmonyOS 分布式任務(wù)調(diào)度的實(shí)現(xiàn)

    鴻蒙HarmonyOS 分布式任務(wù)調(diào)度的實(shí)現(xiàn)

    這篇文章主要介紹了鴻蒙HarmonyOS 分布式任務(wù)調(diào)度的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-09-09
  • Win10 系統(tǒng)下快速搭建mxnet框架cpu版本

    Win10 系統(tǒng)下快速搭建mxnet框架cpu版本

    這篇文章主要介紹了Win10 系統(tǒng)下快速搭建mxnet框架cpu版本,本文圖文并茂給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-10-10
  • 鴻蒙HarmonyO開(kāi)發(fā)實(shí)戰(zhàn)-Web組件中的Cookie及數(shù)據(jù)存儲(chǔ)

    鴻蒙HarmonyO開(kāi)發(fā)實(shí)戰(zhàn)-Web組件中的Cookie及數(shù)據(jù)存儲(chǔ)

    Cookie是一種存儲(chǔ)在用戶(hù)計(jì)算機(jī)上的小文本文件,用于在用戶(hù)訪(fǎng)問(wèn)網(wǎng)站時(shí)存儲(chǔ)和提取信息,它由網(wǎng)站服務(wù)器發(fā)送到用戶(hù)的瀏覽器,并存儲(chǔ)在用戶(hù)的計(jì)算機(jī)上,每當(dāng)用戶(hù)訪(fǎng)問(wèn)該網(wǎng)站時(shí),瀏覽器將發(fā)送該Cookie回服務(wù)器,以用于識(shí)別用戶(hù)和存儲(chǔ)用戶(hù)的首選項(xiàng)和其他信息
    2024-06-06
  • 如何解決Windows的80端口被System進(jìn)程占用問(wèn)題

    如何解決Windows的80端口被System進(jìn)程占用問(wèn)題

    這篇文章主要介紹了如何解決Windows的80端口被System進(jìn)程占用問(wèn)題,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-09-09

最新評(píng)論