|
@@ -19,7 +19,7 @@ import { BusinessError } from '@kit.BasicServicesKit';
|
|
|
import { avSession } from '@kit.AVSessionKit';
|
|
import { avSession } from '@kit.AVSessionKit';
|
|
|
import { BackgroundTaskManager } from '../common/util/BackgroundTaskManager';
|
|
import { BackgroundTaskManager } from '../common/util/BackgroundTaskManager';
|
|
|
import { VideoItem } from '../viewmodel/VideoItem';
|
|
import { VideoItem } from '../viewmodel/VideoItem';
|
|
|
-import { ImageUtil, PreferencesUtil } from '@pura/harmony-utils';
|
|
|
|
|
|
|
+import { ImageUtil, PreferencesUtil, StrUtil } from '@pura/harmony-utils';
|
|
|
import { SettingPage } from '../pages/SettingPage';
|
|
import { SettingPage } from '../pages/SettingPage';
|
|
|
import LyricUtil from '../common/util/LyricUtil';
|
|
import LyricUtil from '../common/util/LyricUtil';
|
|
|
import ImageUtils from '../common/util/ImageUtils';
|
|
import ImageUtils from '../common/util/ImageUtils';
|
|
@@ -32,22 +32,23 @@ export class AvSessionController {
|
|
|
private avSession: avSession.AVSession | undefined = undefined;
|
|
private avSession: avSession.AVSession | undefined = undefined;
|
|
|
private avSessionMetadata: avSession.AVMetadata | undefined = undefined;
|
|
private avSessionMetadata: avSession.AVMetadata | undefined = undefined;
|
|
|
|
|
|
|
|
- constructor(isVideo:boolean) {
|
|
|
|
|
|
|
+ constructor(isVideo: boolean) {
|
|
|
this.initAvSession(isVideo);
|
|
this.initAvSession(isVideo);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static getInstance(isVideo:boolean): AvSessionController {
|
|
|
|
|
|
|
+ public static getInstance(isVideo: boolean): AvSessionController {
|
|
|
if (!AvSessionController.instance) {
|
|
if (!AvSessionController.instance) {
|
|
|
AvSessionController.instance = new AvSessionController(isVideo);
|
|
AvSessionController.instance = new AvSessionController(isVideo);
|
|
|
}
|
|
}
|
|
|
return AvSessionController.instance;
|
|
return AvSessionController.instance;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public initAvSession(isVideo:boolean) {
|
|
|
|
|
- if(isVideo){
|
|
|
|
|
- let isBgPlayOpen = PreferencesUtil.getBooleanSync(SettingPage.IS_BGPLAY_OPEN,true)
|
|
|
|
|
- if(!isBgPlayOpen)
|
|
|
|
|
|
|
+ public initAvSession(isVideo: boolean) {
|
|
|
|
|
+ if (isVideo) {
|
|
|
|
|
+ let isBgPlayOpen = PreferencesUtil.getBooleanSync(SettingPage.IS_BGPLAY_OPEN, true)
|
|
|
|
|
+ if (!isBgPlayOpen) {
|
|
|
return
|
|
return
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
this.context = AppStorage.get('context');
|
|
this.context = AppStorage.get('context');
|
|
@@ -65,7 +66,7 @@ export class AvSessionController {
|
|
|
this.avSession.setExtras({
|
|
this.avSession.setExtras({
|
|
|
requireAbilityList: ['url-cast']
|
|
requireAbilityList: ['url-cast']
|
|
|
});
|
|
});
|
|
|
- }).catch((error:Error) => {
|
|
|
|
|
|
|
+ }).catch((error: Error) => {
|
|
|
console.error('Failed to create AVSession:', error);
|
|
console.error('Failed to create AVSession:', error);
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
@@ -110,7 +111,7 @@ export class AvSessionController {
|
|
|
let metadata: avSession.AVMetadata = {
|
|
let metadata: avSession.AVMetadata = {
|
|
|
assetId: `${curSource.filePath}`,
|
|
assetId: `${curSource.filePath}`,
|
|
|
title: curSource.name,
|
|
title: curSource.name,
|
|
|
- filter: avSession.ProtocolType.TYPE_CAST_PLUS_STREAM|avSession.ProtocolType.TYPE_DLNA,
|
|
|
|
|
|
|
+ filter: avSession.ProtocolType.TYPE_CAST_PLUS_STREAM | avSession.ProtocolType.TYPE_DLNA,
|
|
|
mediaImage: imagePixMap,
|
|
mediaImage: imagePixMap,
|
|
|
duration: duration,
|
|
duration: duration,
|
|
|
// 如果是DRM资源,配置支持的DRM uuid 用于设备过滤。非DRM资源不配置。
|
|
// 如果是DRM资源,配置支持的DRM uuid 用于设备过滤。非DRM资源不配置。
|
|
@@ -126,36 +127,39 @@ export class AvSessionController {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public async setAVMetadataMusic(curSource: VideoItem, duration: number,lyricContent?:string) {
|
|
|
|
|
|
|
+ public async setAVMetadataMusic(curSource: VideoItem, duration: number, lyricContent?: string) {
|
|
|
if (curSource === undefined) {
|
|
if (curSource === undefined) {
|
|
|
hilog.error(0x0000, TAG, 'SetAVMetadata Error, curSource is null');
|
|
hilog.error(0x0000, TAG, 'SetAVMetadata Error, curSource is null');
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
try {
|
|
try {
|
|
|
BackgroundTaskManager.startContinuousTask(this.context);
|
|
BackgroundTaskManager.startContinuousTask(this.context);
|
|
|
- let pixelMapPath:string|undefined = curSource.pixelMapPath
|
|
|
|
|
|
|
|
|
|
- let imagePixMap: PixelMap|string ;
|
|
|
|
|
- if(pixelMapPath){
|
|
|
|
|
- imagePixMap = await ImageUtils.imagePathToPixelMap(pixelMapPath)
|
|
|
|
|
- }else{
|
|
|
|
|
- imagePixMap = await ImageUtil.getPixelMapFromMedia($r('app.media.ic_avatar2'));
|
|
|
|
|
|
|
+ let pixelMapPath: string | undefined = curSource.pixelMapPath
|
|
|
|
|
+ let imagePixMap: PixelMap | string = await ImageUtil.getPixelMapFromMedia($r('app.media.ic_avatar7'));
|
|
|
|
|
+ if (pixelMapPath && StrUtil.isNotEmpty(pixelMapPath)) {
|
|
|
|
|
+ if (pixelMapPath.startsWith('http')) {
|
|
|
|
|
+ imagePixMap = pixelMapPath
|
|
|
|
|
+ } else {
|
|
|
|
|
+ imagePixMap = await ImageUtils.imagePathToPixelMap(pixelMapPath)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
let lyric = ''
|
|
let lyric = ''
|
|
|
- if(lyricContent)
|
|
|
|
|
|
|
+ if (lyricContent) {
|
|
|
lyric = LyricUtil.convertLyricToSimpleLrc(lyricContent)
|
|
lyric = LyricUtil.convertLyricToSimpleLrc(lyricContent)
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- hilog.info(0x0000, TAG, 'onecold SetAVMetadata successfully curSource.pixelMapPath '+curSource.pixelMapPath);
|
|
|
|
|
|
|
+ hilog.info(0x0000, TAG, 'onecold SetAVMetadata successfully curSource.pixelMapPath ' + curSource.pixelMapPath);
|
|
|
let metadata: avSession.AVMetadata = {
|
|
let metadata: avSession.AVMetadata = {
|
|
|
assetId: `${curSource.filePath}`,
|
|
assetId: `${curSource.filePath}`,
|
|
|
title: curSource.name,
|
|
title: curSource.name,
|
|
|
subtitle: curSource.album,
|
|
subtitle: curSource.album,
|
|
|
// 发现Cast+ Stream 和 DLNA协议设备,TYPE_CAST_PLUS_STREAM为默认必选
|
|
// 发现Cast+ Stream 和 DLNA协议设备,TYPE_CAST_PLUS_STREAM为默认必选
|
|
|
- filter: avSession.ProtocolType.TYPE_CAST_PLUS_STREAM|avSession.ProtocolType.TYPE_DLNA,
|
|
|
|
|
|
|
+ filter: avSession.ProtocolType.TYPE_CAST_PLUS_STREAM | avSession.ProtocolType.TYPE_DLNA,
|
|
|
artist: curSource.artist,
|
|
artist: curSource.artist,
|
|
|
mediaImage: imagePixMap,
|
|
mediaImage: imagePixMap,
|
|
|
duration: duration,
|
|
duration: duration,
|
|
|
- lyric:lyric,
|
|
|
|
|
|
|
+ lyric: lyric,
|
|
|
// 如果是DRM资源,配置支持的DRM uuid 用于设备过滤。非DRM资源不配置。
|
|
// 如果是DRM资源,配置支持的DRM uuid 用于设备过滤。非DRM资源不配置。
|
|
|
// drmSchemes: ['3d5e6d35-9b9a-41e8-b843-dd3c6e72c42c']
|
|
// drmSchemes: ['3d5e6d35-9b9a-41e8-b843-dd3c6e72c42c']
|
|
|
};
|
|
};
|