/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ohos.samples.audioplayer;
import ohos.samples.audioplayer.utils.LogUtil;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.ListContainer;
import ohos.agp.components.RecycleItemProvider;
import ohos.agp.components.Text;
import ohos.bundle.ElementName;
import ohos.bundle.IBundleManager;
import ohos.media.common.AVMetadata;
import ohos.media.common.sessioncore.AVConnectionCallback;
import ohos.media.common.sessioncore.AVControllerCallback;
import ohos.media.common.sessioncore.AVElement;
import ohos.media.common.sessioncore.AVPlaybackState;
import ohos.media.common.sessioncore.AVQueueElement;
import ohos.media.common.sessioncore.AVSubscriptionCallback;
import ohos.media.sessioncore.AVBrowser;
import ohos.media.sessioncore.AVController;
import ohos.security.SystemPermission;
import ohos.utils.PacMap;
import ohos.utils.net.Uri;
import java.util.ArrayList;
import java.util.List;
/**
* The client of the player, that implements a AVBrowser.
*/
public class AVPlayClient extends Ability {
private static final String TAG = AVPlayClient.class.getSimpleName();
// provide the main client function of media framework
private AVBrowser avBrowser;
// provide the operations by the avBrowser
private AVController avController;
private Button playButton;
private Button previousButton;
private Button nextButton;
private Text titleText;
private Text progressText;
private Text totalTimeText;
// the media list got from the service
private List<AVElement> avElementList = new ArrayList<>();
private AVElementItemProvider avElementsListItemProvider;
@Override
public void onStart(Intent intent) {
super.onStart(intent);
LogUtil.info(TAG, "onStart");
super.setUIContent(ResourceTable.Layout_main_play_layout);
// bind the handler for all the components
previousButton = (Button) findComponentById(ResourceTable.Id_to_previous_button);
previousButton.setClickedListener(component -> handlerPrevEvent());
nextButton = (Button) findComponentById(ResourceTable.Id_to_next_button);
nextButton.setClickedListener(component -> handlerNextEvent());
playButton = (Button) findComponentById(ResourceTable.Id_play_button);
playButton.setClickedListener(component -> handlerPlayEvent());
titleText = (Text) findComponentById(ResourceTable.Id_audio_title);
progressText = (Text) findComponentById(ResourceTable.Id_audio_progress);
totalTimeText = (Text) findComponentById(ResourceTable.Id_audio_total_time);
ListContainer avElementsListContainer = (ListContainer) findComponentById(ResourceTable.Id_play_list);
avElementsListItemProvider = new AVElementItemProvider();
avElementsListContainer.setItemProvider(avElementsListItemProvider);
Component jumpComponent = findComponentById(ResourceTable.Id_jump_to_next_page_button);
jumpComponent.setClickedListener(component -> jumpOnline());
// init the avBrowser and connect the browser service
ElementName elementName = new ElementName("", AVPlayService.class.getPackage().getName(),
AVPlayService.class.getName());
avBrowser = new AVBrowser(this, elementName, avConnectionCallback, null);
connectService();
}
private void jumpOnline() {
Intent intent = new Intent();
Operation operation = new Intent.OperationBuilder().withBundleName(
OnlinePlayClient.class.getPackage().getName()).withAbilityName(OnlinePlayClient.class.getName()).build();
intent.setOperation(operation);
startAbility(intent);
}
@Override
protected void onStop() {
LogUtil.info(TAG, "onStop");
super.onStop();
Intent intent = new Intent();
Operation operation = new Intent.OperationBuilder().withBundleName(AVPlayService.class.getPackage().getName())
.withAbilityName(AVPlayService.class.getName())
.build();
intent.setOperation(operation);
stopAbility(intent);
if (avBrowser != null && avBrowser.isConnected()) {
avBrowser.disconnect();
}
}
/**
* create the list of audios
*/
class AVElementItemProvider extends RecycleItemProvider {
@Override
public int getCount() {
return avElementList.size();
}
@Override
public Object getItem(int position) {
return avElementList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public Component getComponent(int position, Component component, ComponentContainer componentContainer) {
final Object item = avElementList.get(position);
if (component == null && item instanceof AVElement) {
String itemText = ((AVElement) item).getAVDescription().getTitle().toString();
Text text = (Text) LayoutScatter.getInstance(AVPlayClient.this)
.parse(ResourceTable.Layout_list_item, null, false);
text.setText(itemText);
return text;
} else {
return component;
}
}
};
private AVConnectionCallback avConnectionCallback = new AVConnectionCallback() {
@Override
public void onConnected() {
LogUtil.info(TAG + "-AVConnectionCallback", "onConnected");
// before subscribe, first to unsubscribe, it's necessary.
avBrowser.unsubscribeByParentMediaId(AVPlayService.PARENT_MEDIA_ID_1);
// onLoadAVElementList() on service will be called if subscribed.
avBrowser.subscribeByParentMediaId(AVPlayService.PARENT_MEDIA_ID_1, avSubscriptionCallback);
}
@Override
public void onDisconnected() {
LogUtil.warn(TAG + "-AVConnectionCallback", "onDisconnected");
}
@Override
public void onConnectFailed() {
LogUtil.error(TAG + "-AVConnectionCallback", "onConnectionFailed");
}
};
private AVControllerCallback avControllerCallback = new AVControllerCallback() {
@Override
public void onAVMetadataChanged(AVMetadata metadata) {
// this will be called with avSession.setAVMetadata() called on service.
super.onAVMetadataChanged(metadata);
LogUtil.info(TAG + "-AVControllerCallback", "onAVMetadataChanged");
titleText.setText(metadata.getString(AVMetadata.AVTextKey.TITLE));
totalTimeText.setText(String.valueOf(metadata.getLong(AVMetadata.AVLongKey.DURATION) / 1000));
}
@Override
public void onAVPlaybackStateChanged(AVPlaybackState playbackState) {
// this will be called with avSession.setAVPlaybackState() called on service.
super.onAVPlaybackStateChanged(playbackState);
LogUtil.info(TAG + "-AVControllerCallback", "onAVPlaybackStateChanged");
switch (playbackState.getAVPlaybackState()) {
case AVPlaybac
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
本示例通过注解和继承来实现数据库和表的创建,实现了数据库的升级、备份、删除、恢复,实现了表的增删改查,并监听数据变化。 @Database注解,且继承了OrmDatabase的类,对应关系型数据库; @Entity注解,且继承了OrmObject的类,对应关系型数据库中的表; OrmContext实现数据库的升级、备份、删除、恢复,表的增删改查并监听数据变化。 说明: 点击插入按钮插入数据,点击更新按钮更新数据,点击删除按钮删除数据,点击查询按钮查询数据并显示查询结果; 点击升级按钮数据库升级,从版本1升级到3,会从1升级到2再从2升级到3; 点击备份按钮数据库备份,点击删除数据库按钮删除数据库,点击恢复按钮恢复数据库。
资源推荐
资源详情
资源评论
收起资源包目录
HarmonyOS之实现对象关系映射ORM数据库的升级、备份、删除、恢复以及表的增删改查 (2000个子文件)
index.css 7KB
deliveryInfo.css 7KB
index.css 5KB
index.css 4KB
index.css 3KB
detail.css 3KB
performance.css 3KB
evaluation.css 3KB
index.css 3KB
microAmoy.css 3KB
calc.css 3KB
index.css 2KB
index.css 2KB
index.css 2KB
index.css 2KB
index.css 2KB
bigimg.css 2KB
recommend.css 2KB
index.css 2KB
index.css 2KB
modalhalf.css 2KB
index.css 2KB
index.css 2KB
setPage.css 2KB
index.css 2KB
setPage.css 2KB
index.css 1KB
index.css 1KB
modalpopup.css 1KB
productList.css 1KB
navbar.css 1KB
modalsemimode.css 1KB
index.css 1KB
index.css 1KB
main.css 1KB
compositeanimation.css 1KB
searchbar.css 1KB
index.css 1KB
index.css 1KB
common.css 1KB
translate.css 1KB
common.css 1KB
sharedelement.css 1KB
index.css 1KB
customtarget.css 1KB
sharedtargetpage.css 1KB
index.css 1KB
rotate.css 1KB
index.css 1KB
scale.css 1KB
index.css 1KB
index.css 1KB
index.css 1KB
success.css 1KB
recommended.css 1KB
index.css 1KB
coreModule.css 1KB
login.css 1KB
index.css 1KB
customtransition.css 1018B
index.css 1012B
index.css 994B
common.css 988B
common.css 988B
splash.css 974B
index.css 963B
second.css 963B
comp.css 963B
index.css 951B
index.css 949B
banner.css 908B
commoditys.css 897B
cardtransition.css 892B
pageHome.css 828B
cardtargetpage.css 817B
index.css 817B
bannerSwiper.css 815B
mainContent.css 806B
index.css 792B
index.css 792B
index.css 791B
details.css 763B
._index.css 212B
._index.css 212B
._splash.css 212B
._main.css 212B
._login.css 212B
._index.css 212B
._second.css 212B
._index.css 212B
._calc.css 212B
._index.css 212B
._index.css 212B
._index.css 212B
._comp.css 212B
._index.css 212B
._details.css 212B
._index.css 212B
._modalpopup.css 212B
._modalhalf.css 212B
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
靛蓝勇士
- 粉丝: 17
- 资源: 45
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功