女人自慰AV免费观看内涵网,日韩国产剧情在线观看网址,神马电影网特片网,最新一级电影欧美,在线观看亚洲欧美日韩,黄色视频在线播放免费观看,ABO涨奶期羡澄,第一导航fulione,美女主播操b

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

鴻蒙系統(tǒng)中用Java UI開發(fā)分布式仿抖音應(yīng)用

OpenHarmony技術(shù)社區(qū) ? 來源:鴻蒙技術(shù)社區(qū) ? 作者:開鴻HOS小鴻 ? 2021-11-01 14:49 ? 次閱讀

本文使用 Java UI 開發(fā)分布式仿抖音應(yīng)用,上下滑動切換視頻,評論功能,設(shè)備遷移功能:記錄播放的視頻頁和進度、評論數(shù)據(jù)。

效果演示

①上下滑動切換視頻、點擊遷移圖標,彈框選擇在線的設(shè)備,完成視頻數(shù)據(jù)的遷移。

點擊評論圖標查看評論,編輯評論內(nèi)容并發(fā)送。點擊遷移圖標,彈框選擇在線的設(shè)備,完成評論數(shù)據(jù)的遷移。

項目結(jié)構(gòu)

如下圖:

d2044b64-3ac4-11ec-82a9-dac502259ad0.png

主要代碼

①上下滑動頁面

頁面切換用到系統(tǒng)組件PageSlider:

https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ui-java-component-pageslider-0000001091933258

默認左右切換,設(shè)置為上下方向:setOrientation(Component.VERTICAL);

importohos.aafwk.ability.AbilitySlice;
importohos.aafwk.content.Intent;
importohos.agp.components.*;

importjava.util.ArrayList;
importjava.util.List;

publicclassMainAbilitySliceextendsAbilitySlice{
@Override
publicvoidonStart(Intentintent){
super.onStart(intent);
super.setUIContent(ResourceTable.Layout_ability_main);
//查找滑動頁面組件
PageSliderpageSlider=(PageSlider)findComponentById(ResourceTable.Id_pageSlider);
//設(shè)置滑動方向為上下滑動
pageSlider.setOrientation(Component.VERTICAL);
//集合測試數(shù)據(jù)
ListlistData=newArrayList<>();
listData.add("第一頁");
listData.add("第二頁");
listData.add("第三頁");

//設(shè)置頁面適配器
pageSlider.setProvider(newPageSliderProvider(){
/**
*獲取當前適配器中可用視圖的數(shù)量
*/
@Override
publicintgetCount(){
returnlistData.size();
}
/**
*創(chuàng)建頁面
*/
@Override
publicObjectcreatePageInContainer(ComponentContainercontainer,intposition){
//查找布局
Componentcomponent=LayoutScatter.getInstance(getContext()).parse(ResourceTable.Layout_item_page,null,false);
TexttextContent=(Text)component.findComponentById(ResourceTable.Id_text_item_page_content);
//設(shè)置數(shù)據(jù)
textContent.setText(listData.get(position));
//添加到容器中
container.addComponent(component);
returncomponent;
}
/**
*銷毀頁面
*/
@Override
publicvoiddestroyPageFromContainer(ComponentContainercontainer,intposition,Objectobject){
//從容器中移除
container.removeComponent((Component)object);
}
/**
*檢查頁面是否與對象匹配
*/
@Override
publicbooleanisPageMatchToObject(Componentpage,Objectobject){
returntrue;
}
});

//添加頁面改變監(jiān)聽器
pageSlider.addPageChangedListener(newPageSlider.PageChangedListener(){
/**
*頁面滑動時調(diào)用
*/
@Override
publicvoidonPageSliding(intitemPos,floatitemPosOffset,intitemPosOffsetPixels){}
/**
*當頁面滑動狀態(tài)改變時調(diào)用
*/
@Override
publicvoidonPageSlideStateChanged(intstate){}
/**
*選擇新頁面時回調(diào)
*/
@Override
publicvoidonPageChosen(intitemPos){
//在此方法下,切換頁面獲取當前頁面的視頻源,進行播放
Stringdata=listData.get(itemPos);
}
});
}
}

②播放視頻

視頻播放使用Player:

https://developer.harmonyos.com/cn/docs/documentation/doc-guides/media-video-player-0000000000044178

視頻畫面窗口顯示使用SurfaceProvider:

https://developer.harmonyos.com/cn/docs/documentation/doc-guides/faq-media-0000001124842486#section0235506211
importohos.aafwk.ability.AbilitySlice;
importohos.aafwk.content.Intent;
importohos.agp.components.surfaceprovider.SurfaceProvider;
importohos.agp.graphics.SurfaceOps;
importohos.global.resource.RawFileDescriptor;
importohos.media.common.Source;
importohos.media.player.Player;

importjava.io.IOException;

publicclassMainAbilitySliceextendsAbilitySlice{
//視頻路徑
privatefinalStringvideoPath="resources/rawfile/HarmonyOS.mp4";
//播放器
privatePlayermPlayer;

@Override
publicvoidonStart(Intentintent){
super.onStart(intent);
super.setUIContent(ResourceTable.Layout_ability_main);
//初始化播放器
mPlayer=newPlayer(getContext());
//查找視頻窗口組件
SurfaceProvidersurfaceProvider=(SurfaceProvider)findComponentById(ResourceTable.Id_surfaceProvider);
//設(shè)置視頻窗口在頂層
surfaceProvider.pinToZTop(true);
//設(shè)置視頻窗口操作監(jiān)聽
if(surfaceProvider.getSurfaceOps().isPresent()){
surfaceProvider.getSurfaceOps().get().addCallback(newSurfaceOps.Callback(){
/**
*創(chuàng)建視頻窗口
*/
@Override
publicvoidsurfaceCreated(SurfaceOpsholder){
try{
RawFileDescriptorfileDescriptor=getResourceManager().getRawFileEntry(videoPath).openRawFileDescriptor();
Sourcesource=newSource(fileDescriptor.getFileDescriptor(),
fileDescriptor.getStartPosition(),
fileDescriptor.getFileSize()
);
//設(shè)置媒體文件
mPlayer.setSource(source);
//設(shè)置播放窗口
mPlayer.setVideoSurface(holder.getSurface());
//循環(huán)播放
mPlayer.enableSingleLooping(true);
//準備播放環(huán)境并緩沖媒體數(shù)據(jù)
mPlayer.prepare();
//開始播放
mPlayer.play();
}catch(IOExceptione){
e.printStackTrace();
}

}
/**
*視頻窗口改變
*/
@Override
publicvoidsurfaceChanged(SurfaceOpsholder,intformat,intwidth,intheight){}
/**
*視頻窗口銷毀
*/
@Override
publicvoidsurfaceDestroyed(SurfaceOpsholder){}
});
}
}

@Override
protectedvoidonStop(){
super.onStop();
//頁面銷毀,釋放播放器
if(mPlayer!=null){
mPlayer.stop();
mPlayer.release();
}
}
}

③跨設(shè)備遷移示例

跨設(shè)備遷移使用IAbilityContinuation 接口

https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ability-page-cross-device-0000001051072880

在 entry 下的 config.json 配置權(quán)限:

"reqPermissions":[
{
"name":"ohos.permission.DISTRIBUTED_DATASYNC"
},
{
"name":"ohos.permission.GET_DISTRIBUTED_DEVICE_INFO"
},
{
"name":"ohos.permission.DISTRIBUTED_DEVICE_STATE_CHANGE"
}
]

實現(xiàn) IAbilityContinuation 接口,說明:一個應(yīng)用可能包含多個 Page,僅需要在支持遷移的 Page 中通過以下方法實現(xiàn) IAbilityContinuation 接口。

同時,此 Page 所包含的所有 AbilitySlice 也需要實現(xiàn)此接口。

importohos.aafwk.ability.AbilitySlice;
importohos.aafwk.ability.IAbilityContinuation;
importohos.aafwk.content.Intent;
importohos.aafwk.content.IntentParams;
importohos.agp.components.Button;
importohos.agp.components.Text;
importohos.bundle.IBundleManager;
importohos.distributedschedule.interwork.DeviceInfo;
importohos.distributedschedule.interwork.DeviceManager;

importjava.util.List;

publicclassMainAbilitySliceextendsAbilitySliceimplementsIAbilityContinuation{
privateStringdata="";
StringPERMISSION="ohos.permission.DISTRIBUTED_DATASYNC";

@Override
publicvoidonStart(Intentintent){
super.onStart(intent);
super.setUIContent(ResourceTable.Layout_ability_main);
//申請權(quán)限
if(verifySelfPermission(PERMISSION)!=IBundleManager.PERMISSION_GRANTED){
requestPermissionsFromUser(newString[]{PERMISSION},0);
}
Buttonbutton=(Button)findComponentById(ResourceTable.Id_button);
Texttext=(Text)findComponentById(ResourceTable.Id_text);

//點擊遷移
button.setClickedListener(component->{
//查詢分布式網(wǎng)絡(luò)中所有在線設(shè)備(不包括本地設(shè)備)的信息。
ListdeviceList=DeviceManager.getDeviceList(DeviceInfo.FLAG_GET_ONLINE_DEVICE);
if(deviceList.size()>0){
//啟動遷移,指定的設(shè)備ID
continueAbility(deviceList.get(0).getDeviceId());
}
});
//顯示遷移的數(shù)據(jù)
text.setText("遷移的數(shù)據(jù):"+data);
}
/**
*啟動遷移時首次調(diào)用此方法
*@return是否進行遷移
*/
@Override
publicbooleanonStartContinuation(){
returntrue;
}
/**
*遷移時存入數(shù)據(jù)
*/
@Override
publicbooleanonSaveData(IntentParamsintentParams){
intentParams.setParam("data","測試數(shù)據(jù)");
returntrue;
}
/**
*獲取遷移存入的數(shù)據(jù),在生命周期的onStart之前執(zhí)行
*/
@Override
publicbooleanonRestoreData(IntentParamsintentParams){
data=(String)intentParams.getParam("data");
returntrue;
}
/**
*遷移完成
*/
@Override
publicvoidonCompleteContinuation(inti){}
}

根據(jù)上面的核心代碼示例,了解實現(xiàn)原理,接下來便可以結(jié)合實際需求完善功能了。

責任編輯:haq

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學習之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • JAVA
    +關(guān)注

    關(guān)注

    20

    文章

    2984

    瀏覽量

    106855
  • 鴻蒙系統(tǒng)
    +關(guān)注

    關(guān)注

    183

    文章

    2639

    瀏覽量

    67700
  • HarmonyOS
    +關(guān)注

    關(guān)注

    79

    文章

    2052

    瀏覽量

    32120

原文標題:開發(fā)一個鴻蒙版“抖音”,So easy!

文章出處:【微信號:gh_834c4b3d87fe,微信公眾號:OpenHarmony技術(shù)社區(qū)】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。

收藏 人收藏

    評論

    相關(guān)推薦
    熱點推薦

    安科瑞Acrel-1000DP分布式光伏監(jiān)控系統(tǒng)在嘉興亨泰分布式光伏項目中的應(yīng)用

    摘要 分布式光伏發(fā)電系統(tǒng)其核心特點是發(fā)電設(shè)備靠近用電負荷中心,通常安裝在屋頂、建筑立面或閑置空地上,截至2025年,分布式光伏發(fā)電系統(tǒng)在全球和中國范圍內(nèi)取得了顯著發(fā)展,成為能源轉(zhuǎn)型和可
    的頭像 發(fā)表于 04-10 13:17 ?203次閱讀
    安科瑞Acrel-1000DP<b class='flag-5'>分布式</b>光伏監(jiān)控<b class='flag-5'>系統(tǒng)</b>在嘉興亨泰<b class='flag-5'>分布式</b>光伏項目中的應(yīng)用

    分布式光伏發(fā)運維系統(tǒng)實際應(yīng)用案例分享

    安科瑞劉鴻鵬 摘?要 分布式光伏發(fā)電系統(tǒng)其核心特點是發(fā)電設(shè)備靠近用電負荷中心,通常安裝在屋頂、建筑立面或閑置空地上,截至2025年,分布式光伏發(fā)電系統(tǒng)在全球和中國范圍內(nèi)取得了顯著發(fā)展,
    的頭像 發(fā)表于 04-09 14:46 ?214次閱讀
    <b class='flag-5'>分布式</b>光伏發(fā)運維<b class='flag-5'>系統(tǒng)</b>實際應(yīng)用案例分享

    淺談分布式光伏系統(tǒng)在工業(yè)企業(yè)的設(shè)計及應(yīng)用

    主要對工業(yè)廠區(qū)屋頂分布式光伏發(fā)電系統(tǒng)的設(shè)計及應(yīng)用進行研究,為工業(yè)廠區(qū)能源供應(yīng)提供一種全新的解決思路和技術(shù)支持。介紹了工業(yè)廠區(qū)屋頂分布式光伏系統(tǒng)及其優(yōu)勢,分析了工業(yè)廠區(qū)屋頂
    的頭像 發(fā)表于 03-21 14:24 ?348次閱讀
    淺談<b class='flag-5'>分布式</b>光伏<b class='flag-5'>系統(tǒng)</b>在工業(yè)企業(yè)的設(shè)計及應(yīng)用

    【「鴻蒙操作系統(tǒng)設(shè)計原理與架構(gòu)」閱讀體驗】02-華為鴻蒙設(shè)計理念

    多種不同類型的 HarmonyOS 設(shè)備上,大大節(jié)省了開發(fā)時間和成本 。 分布式 UI 框架是 DevEco Studio 的另一大亮點,它為開發(fā)者提供了一套統(tǒng)一的
    發(fā)表于 02-23 16:16

    分布式云化數(shù)據(jù)庫有哪些類型

    分布式云化數(shù)據(jù)庫有哪些類型?分布式云化數(shù)據(jù)庫主要類型包括:關(guān)系型分布式數(shù)據(jù)庫、非關(guān)系型分布式數(shù)據(jù)庫、新SQL分布式數(shù)據(jù)庫、以列方式存儲數(shù)據(jù)、
    的頭像 發(fā)表于 01-15 09:43 ?386次閱讀

    AIGC入門及鴻蒙入門

    JDK、配置SDK等。 3. 開發(fā)實踐: 學習鴻蒙系統(tǒng)的架構(gòu)和API,了解其組件化、分布式等特性。 通過官方文檔和社區(qū)資源,學習和掌握鴻蒙應(yīng)
    發(fā)表于 01-13 10:32

    基于ptp的分布式系統(tǒng)設(shè)計

    在現(xiàn)代分布式系統(tǒng)中,精確的時間同步對于確保數(shù)據(jù)一致性、系統(tǒng)穩(wěn)定性和性能至關(guān)重要。PTP(Precision Time Protocol)是一種網(wǎng)絡(luò)協(xié)議,用于在分布式
    的頭像 發(fā)表于 12-29 10:09 ?450次閱讀

    HarmonyOS Next 應(yīng)用元服務(wù)開發(fā)-分布式數(shù)據(jù)對象遷移數(shù)據(jù)文件資產(chǎn)遷移

    提供了async版本供該場景使用。 當前,wantParams中“sessionId”字段在遷移流程中被系統(tǒng)占用,建議開發(fā)者在wantParams中定義其他key值存儲該分布式數(shù)據(jù)對象生成的id,避免
    發(fā)表于 12-24 10:11

    HarmonyOS Next 應(yīng)用元服務(wù)開發(fā)-分布式數(shù)據(jù)對象遷移數(shù)據(jù)權(quán)限與基礎(chǔ)數(shù)據(jù)

    提供了async版本供該場景使用。 當前,wantParams中“sessionId”字段在遷移流程中被系統(tǒng)占用,建議開發(fā)者在wantParams中定義其他key值存儲該分布式數(shù)據(jù)對象生成的id,避免
    發(fā)表于 12-24 09:40

    名單公布!【書籍評測活動NO.53】鴻蒙操作系統(tǒng)設(shè)計原理與架構(gòu)

    的底層設(shè)計邏輯出發(fā),針對不同關(guān)鍵子系統(tǒng)的目標功能和實現(xiàn)路徑做實際分析解讀,幫助開發(fā)者理解鴻蒙操作系統(tǒng)的底層邏輯,開發(fā)更適合
    發(fā)表于 12-16 15:10

    鴻蒙開發(fā)管理:ohos.account.distributedAccount 分布式帳號管理

    獲取分布式帳號單實例對象。
    的頭像 發(fā)表于 07-08 10:03 ?434次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>開發(fā)</b>管理:ohos.account.distributedAccount <b class='flag-5'>分布式</b>帳號管理

    分布式光纖測溫系統(tǒng)DTS

    隨著城市用電量的持續(xù)增長,電纜負荷日益加重,電纜故障頻發(fā)成為一個不容忽視的問題。傳統(tǒng)的電纜監(jiān)測手段已經(jīng)無法滿足對電纜狀態(tài)實時、精準監(jiān)控的需求,因此部分供電公司采用鼎信分布式光纖測溫系統(tǒng)(DTS)來
    的頭像 發(fā)表于 06-27 17:18 ?991次閱讀

    鴻蒙ArkTS聲明開發(fā):跨平臺支持列表【分布式遷移標識】 通用屬性

    組件的分布式遷移標識,指明了該組件在分布式遷移場景下可以將特定狀態(tài)恢復到對端設(shè)備。
    的頭像 發(fā)表于 06-07 21:15 ?585次閱讀

    分布式SCADA系統(tǒng)的特點的組成

    在工業(yè)自動化和能源管理領(lǐng)域,SCADA(Supervisory Control And Data Acquisition)系統(tǒng)扮演著至關(guān)重要的角色。其中,分布式SCADA系統(tǒng)憑借其獨特的結(jié)構(gòu)和功能
    的頭像 發(fā)表于 06-07 14:43 ?869次閱讀

    鴻蒙開發(fā)接口數(shù)據(jù)管理:【@ohos.data.distributedData (分布式數(shù)據(jù)管理)】

    分布式數(shù)據(jù)管理為應(yīng)用程序提供不同設(shè)備間數(shù)據(jù)庫的分布式協(xié)同能力。通過調(diào)用分布式數(shù)據(jù)各個接口,應(yīng)用程序可將數(shù)據(jù)保存到分布式數(shù)據(jù)庫中,并可對分布式
    的頭像 發(fā)表于 06-07 09:30 ?1421次閱讀
    <b class='flag-5'>鴻蒙</b><b class='flag-5'>開發(fā)</b>接口數(shù)據(jù)管理:【@ohos.data.distributedData (<b class='flag-5'>分布式</b>數(shù)據(jù)管理)】