fix: 视频优化
This commit is contained in:
parent
36490c4797
commit
690f28381f
@ -76,17 +76,11 @@ struct Index {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async onPageShow(): Promise<void> {
|
async onPageShow(): Promise<void> {
|
||||||
this.baseInfo = AppStorage.get<BaseInfoType>('baseInfo')!
|
|
||||||
await UseAuth(this.context)
|
await UseAuth(this.context)
|
||||||
|
this.avPlayer.playAudio(['welcome.wav'])
|
||||||
|
this.baseInfo = AppStorage.get<BaseInfoType>('baseInfo')!
|
||||||
this.initParams()
|
this.initParams()
|
||||||
AppStorage.setOrCreate('singlePlay', false)
|
AppStorage.setOrCreate('singlePlay', false)
|
||||||
this.context.resourceManager.getRawFileContent("welcome.wav")
|
|
||||||
.then(() => {
|
|
||||||
this.avPlayer.playAudio(['welcome.wav'])
|
|
||||||
})
|
|
||||||
.catch((error: BusinessError) => {
|
|
||||||
console.log("getRawFileContent promise error is " + error);
|
|
||||||
});
|
|
||||||
this.num = 0
|
this.num = 0
|
||||||
AppStorage.setOrCreate('lsh', '1111111111111')
|
AppStorage.setOrCreate('lsh', '1111111111111')
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,18 @@
|
|||||||
import { VideoConfigData } from '../mock'
|
import { VideoConfigData } from '../mock'
|
||||||
import { VideoConfig, VideoItemType } from '../model'
|
import { RecordHandleType, VideoConfig, VideoItemType } from '../model'
|
||||||
|
import FileUtils from '../utils/FileUtils'
|
||||||
import HeaderComponent from './compontents/Header'
|
import HeaderComponent from './compontents/Header'
|
||||||
import VideoConfigComponent from './VideoConfig/Config'
|
import VideoConfigComponent from './VideoConfig/Config'
|
||||||
|
import common from '@ohos.app.ability.common'
|
||||||
|
import { GlobalConfig } from '../config'
|
||||||
|
import Prompt from '@system.prompt'
|
||||||
|
import { endRecordVideo, startRecordVideo, takePhoto } from '../utils/Video'
|
||||||
|
|
||||||
@Entry
|
@Entry
|
||||||
@Component
|
@Component
|
||||||
struct VideoConfigPage {
|
struct VideoConfigPage {
|
||||||
@State videoConfig: VideoConfig = VideoConfigData
|
@State videoConfig: VideoConfig = VideoConfigData
|
||||||
|
@State oldVideoConfig: VideoConfig = VideoConfigData
|
||||||
@State curRate: PlaybackSpeed = PlaybackSpeed.Speed_Forward_1_00_X
|
@State curRate: PlaybackSpeed = PlaybackSpeed.Speed_Forward_1_00_X
|
||||||
@State openFlag: boolean = true
|
@State openFlag: boolean = true
|
||||||
// 是否自动播放
|
// 是否自动播放
|
||||||
@ -15,11 +21,29 @@ struct VideoConfigPage {
|
|||||||
// 弹窗
|
// 弹窗
|
||||||
dialogController: CustomDialogController = new CustomDialogController({
|
dialogController: CustomDialogController = new CustomDialogController({
|
||||||
builder: VideoConfigComponent({
|
builder: VideoConfigComponent({
|
||||||
videoConfig: this.videoConfig
|
videoConfig: this.videoConfig,
|
||||||
|
back: () => {
|
||||||
|
console.log("返回")
|
||||||
|
this.videoConfig = this.oldVideoConfig
|
||||||
|
},
|
||||||
|
save: (config: VideoConfig) => {
|
||||||
|
console.log("保存", config)
|
||||||
|
this.videoConfig = config
|
||||||
|
this.saveVideoConfig()
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
alignment: DialogAlignment.Bottom,
|
alignment: DialogAlignment.Bottom,
|
||||||
customStyle: true
|
customStyle: true
|
||||||
})
|
})
|
||||||
|
@State recordHandleObj: RecordHandleType = {
|
||||||
|
rocord_handle1: 0,
|
||||||
|
rocord_handle2: 0,
|
||||||
|
rocord_handle3: 0,
|
||||||
|
rocord_handle4: 0
|
||||||
|
}
|
||||||
|
// 文件操作
|
||||||
|
private fileUtil: FileUtils
|
||||||
|
private context = getContext(this) as common.UIAbilityContext;
|
||||||
// 视频控制器
|
// 视频控制器
|
||||||
private controller1: VideoController = new VideoController()
|
private controller1: VideoController = new VideoController()
|
||||||
private controller2: VideoController = new VideoController()
|
private controller2: VideoController = new VideoController()
|
||||||
@ -33,6 +57,37 @@ struct VideoConfigPage {
|
|||||||
{ td: 'td4', controller: this.controller4, src: '' },
|
{ td: 'td4', controller: this.controller4, src: '' },
|
||||||
]
|
]
|
||||||
|
|
||||||
|
aboutToAppear(): void {
|
||||||
|
this.fileUtil = new FileUtils(this.context)
|
||||||
|
this.readVideoConfig()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取视频配置
|
||||||
|
async readVideoConfig() {
|
||||||
|
const data = await this.fileUtil.readFile(GlobalConfig.commonFileWriteAddress + '/config/config3.txt');
|
||||||
|
this.videoConfig = JSON.parse(data)
|
||||||
|
this.oldVideoConfig = JSON.parse(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存视频配置
|
||||||
|
async saveVideoConfig() {
|
||||||
|
const folderPath = await this.fileUtil.initFolder(`/config`);
|
||||||
|
console.log(this.oldVideoConfig.videoNum, this.videoConfig.videoNum, "查看")
|
||||||
|
this.fileUtil.addFile(`${folderPath}/config3.txt`, JSON.stringify(this.videoConfig))
|
||||||
|
}
|
||||||
|
|
||||||
|
async getFileHandleCode(td: number): Promise<Boolean> {
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
|
try {
|
||||||
|
const record_handle = await startRecordVideo(this.videoConfig, td, this.context, 'lp')
|
||||||
|
Reflect.set(this.recordHandleObj, 'rocord_handle' + td, record_handle)
|
||||||
|
resolve(true)
|
||||||
|
} catch (error) {
|
||||||
|
reject(false)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
Flex({
|
Flex({
|
||||||
justifyContent: FlexAlign.SpaceBetween,
|
justifyContent: FlexAlign.SpaceBetween,
|
||||||
@ -80,22 +135,65 @@ struct VideoConfigPage {
|
|||||||
// 录像
|
// 录像
|
||||||
ButtonComponent({
|
ButtonComponent({
|
||||||
type: "1",
|
type: "1",
|
||||||
click: () => {
|
click: async () => {
|
||||||
this.dialogController.open()
|
if (!this.videoConfig.videoRecord4 && !this.videoConfig.videoRecord3 && !this.videoConfig.videoRecord2 && !this.videoConfig.videoRecord1) {
|
||||||
|
Prompt.showToast({
|
||||||
|
message: '请选择录像通道',
|
||||||
|
duration: 3000
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 1; i <= 4; i++) {
|
||||||
|
if (Reflect.get(this.videoConfig, 'videoRecord' + i)) {
|
||||||
|
await this.getFileHandleCode(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 录像开始
|
||||||
|
Prompt.showToast({
|
||||||
|
message: '录像开始!',
|
||||||
|
duration: 3000
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// 停止
|
// 停止
|
||||||
ButtonComponent({
|
ButtonComponent({
|
||||||
type: "2",
|
type: "2",
|
||||||
click: () => {
|
click: () => {
|
||||||
this.dialogController.open()
|
for (let i = 1; i <= 4; i++) {
|
||||||
|
if (Reflect.get(this.recordHandleObj, 'rocord_handle' + i) !== 0) {
|
||||||
|
endRecordVideo(Reflect.get(this.recordHandleObj, 'rocord_handle' + i))
|
||||||
|
Reflect.set(this.recordHandleObj, 'rocord_handle' + i, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Prompt.showToast({
|
||||||
|
message: '录像已停止!',
|
||||||
|
duration: 3000
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// 抓图
|
// 抓图
|
||||||
ButtonComponent({
|
ButtonComponent({
|
||||||
type: "3",
|
type: "3",
|
||||||
click: () => {
|
click: async () => {
|
||||||
this.dialogController.open()
|
const arr = ['1', '2', '3', '4']
|
||||||
|
if (!arr.includes(this.videoConfig.pztd)) {
|
||||||
|
Prompt.showToast({
|
||||||
|
message: '请填写正确的拍照通道',
|
||||||
|
duration: 3000
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await takePhoto(this.videoConfig, this.context, 'pz/')
|
||||||
|
Prompt.showToast({
|
||||||
|
message: '抓图完成',
|
||||||
|
duration: 3000
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
console.log("抓图失败", error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,8 @@ import TextInputComponent from './TextInput';
|
|||||||
@CustomDialog
|
@CustomDialog
|
||||||
export default struct VideoConfigComponent {
|
export default struct VideoConfigComponent {
|
||||||
@Prop videoConfig: VideoConfig
|
@Prop videoConfig: VideoConfig
|
||||||
|
save?: (value: VideoConfig) => void;
|
||||||
|
back?: () => void;
|
||||||
private controller?: CustomDialogController;
|
private controller?: CustomDialogController;
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
@ -20,9 +22,11 @@ export default struct VideoConfigComponent {
|
|||||||
Row() {
|
Row() {
|
||||||
Image($r('app.media.fh')).height(55).objectFit(ImageFit.Contain).onClick(() => {
|
Image($r('app.media.fh')).height(55).objectFit(ImageFit.Contain).onClick(() => {
|
||||||
this.controller?.close()
|
this.controller?.close()
|
||||||
|
this.back?.();
|
||||||
})
|
})
|
||||||
Image($r('app.media.bc')).height(55).objectFit(ImageFit.Contain).onClick(() => {
|
Image($r('app.media.bc')).height(55).objectFit(ImageFit.Contain).onClick(() => {
|
||||||
console.log(JSON.stringify(this.videoConfig))
|
this.controller?.close()
|
||||||
|
this.save?.(this.videoConfig);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}.padding({
|
}.padding({
|
||||||
@ -93,16 +97,36 @@ export default struct VideoConfigComponent {
|
|||||||
Column() {
|
Column() {
|
||||||
titleComponent()
|
titleComponent()
|
||||||
blockComponent({
|
blockComponent({
|
||||||
label: "第一路"
|
label: "第一路",
|
||||||
|
num: 1,
|
||||||
|
videoConfig: this.videoConfig,
|
||||||
|
change: (value: VideoConfig) => {
|
||||||
|
this.videoConfig = value;
|
||||||
|
}
|
||||||
})
|
})
|
||||||
blockComponent({
|
blockComponent({
|
||||||
label: "第二路"
|
label: "第二路",
|
||||||
|
num: 2,
|
||||||
|
videoConfig: this.videoConfig,
|
||||||
|
change: (value: VideoConfig) => {
|
||||||
|
this.videoConfig = value;
|
||||||
|
}
|
||||||
})
|
})
|
||||||
blockComponent({
|
blockComponent({
|
||||||
label: "第三路"
|
label: "第三路",
|
||||||
|
num: 3,
|
||||||
|
videoConfig: this.videoConfig,
|
||||||
|
change: (value: VideoConfig) => {
|
||||||
|
this.videoConfig = value;
|
||||||
|
}
|
||||||
})
|
})
|
||||||
blockComponent({
|
blockComponent({
|
||||||
label: "第四路"
|
label: "第四路",
|
||||||
|
num: 4,
|
||||||
|
videoConfig: this.videoConfig,
|
||||||
|
change: (value: VideoConfig) => {
|
||||||
|
this.videoConfig = value;
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}.width("75%")
|
}.width("75%")
|
||||||
|
|
||||||
@ -215,6 +239,9 @@ export default struct VideoConfigComponent {
|
|||||||
@Component
|
@Component
|
||||||
struct blockComponent {
|
struct blockComponent {
|
||||||
@State label: string = "第一路"
|
@State label: string = "第一路"
|
||||||
|
@Prop videoConfig: VideoConfig
|
||||||
|
@State num: number = 1
|
||||||
|
change?: (value: VideoConfig) => void;
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
Row() {
|
Row() {
|
||||||
@ -224,28 +251,49 @@ struct blockComponent {
|
|||||||
|
|
||||||
// IP地址
|
// IP地址
|
||||||
TextInputComponent({
|
TextInputComponent({
|
||||||
value: "",
|
value: this.videoConfig.ip,
|
||||||
widthValue: 200
|
widthValue: 200,
|
||||||
|
change: (value: string) => {
|
||||||
|
this.videoConfig.ip = value;
|
||||||
|
this.change?.(this.videoConfig);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// 通道号
|
// 通道号
|
||||||
TextInputComponent({
|
TextInputComponent({
|
||||||
value: "",
|
value: Reflect.get(this.videoConfig, `td${this.num}`) || '',
|
||||||
widthValue: 100
|
widthValue: 100,
|
||||||
|
change: (value: string) => {
|
||||||
|
Reflect.set(this.videoConfig, `td${this.num}`, value);
|
||||||
|
this.change?.(this.videoConfig);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
// 用户名
|
// 用户名
|
||||||
TextInputComponent({
|
TextInputComponent({
|
||||||
value: "",
|
value: this.videoConfig.userName,
|
||||||
widthValue: 200
|
widthValue: 200,
|
||||||
|
change: (value: string) => {
|
||||||
|
this.videoConfig.userName = value;
|
||||||
|
this.change?.(this.videoConfig);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
// 密码
|
// 密码
|
||||||
TextInputComponent({
|
TextInputComponent({
|
||||||
value: "",
|
value: this.videoConfig.pwd,
|
||||||
widthValue: 200
|
widthValue: 200,
|
||||||
|
change: (value: string) => {
|
||||||
|
this.videoConfig.pwd = value;
|
||||||
|
this.change?.(this.videoConfig);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
// 端口号
|
// 端口号
|
||||||
TextInputComponent({
|
TextInputComponent({
|
||||||
value: "",
|
value: this.videoConfig.port,
|
||||||
widthValue: 100
|
widthValue: 100,
|
||||||
|
change: (value: string) => {
|
||||||
|
this.videoConfig.port = value;
|
||||||
|
this.change?.(this.videoConfig);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}.margin({
|
}.margin({
|
||||||
top: 10
|
top: 10
|
||||||
@ -264,14 +312,6 @@ struct partitionSpace {
|
|||||||
|
|
||||||
@Component
|
@Component
|
||||||
struct titleComponent {
|
struct titleComponent {
|
||||||
@Styles
|
|
||||||
commStyle(){
|
|
||||||
.width(220)
|
|
||||||
.height(69)
|
|
||||||
.backgroundImage($r('app.media.button_nor'))
|
|
||||||
.backgroundImageSize({ width: '100%', height: '100%' })
|
|
||||||
}
|
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
Row() {
|
Row() {
|
||||||
Row() {
|
Row() {
|
||||||
|
|||||||
@ -29,6 +29,7 @@ export default class VoiceAnnounce {
|
|||||||
async playAudio(urls: string[], shit?: boolean, callbackFn?: Function) {
|
async playAudio(urls: string[], shit?: boolean, callbackFn?: Function) {
|
||||||
const isStopped = this.isStopped;
|
const isStopped = this.isStopped;
|
||||||
const queue = this.queue;
|
const queue = this.queue;
|
||||||
|
console.log(TAG, "播放")
|
||||||
|
|
||||||
const tempUrls: Queue[] = urls.map((url, index) => {
|
const tempUrls: Queue[] = urls.map((url, index) => {
|
||||||
const callback: Function | undefined = (index === urls.length - 1) ? callbackFn : undefined
|
const callback: Function | undefined = (index === urls.length - 1) ? callbackFn : undefined
|
||||||
@ -94,6 +95,7 @@ class AVPlayer {
|
|||||||
|
|
||||||
// 以下为使用资源管理接口获取打包在HAP内的媒体资源文件并通过fdSrc属性进行播放示例
|
// 以下为使用资源管理接口获取打包在HAP内的媒体资源文件并通过fdSrc属性进行播放示例
|
||||||
async play(name: string, callback: Function): Promise<boolean> {
|
async play(name: string, callback: Function): Promise<boolean> {
|
||||||
|
console.log(TAG, 'play => 开始播放语音')
|
||||||
try {
|
try {
|
||||||
//检查SD中的语音
|
//检查SD中的语音
|
||||||
// console.info('surenjun name',name)
|
// console.info('surenjun name',name)
|
||||||
@ -128,7 +130,7 @@ class AVPlayer {
|
|||||||
this.endCallback = callback
|
this.endCallback = callback
|
||||||
this.avPlayer = await media.createAVPlayer();
|
this.avPlayer = await media.createAVPlayer();
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
await this.setAVPlayerCallback(() => {
|
this.setAVPlayerCallback(() => {
|
||||||
resolve(true)
|
resolve(true)
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
@ -148,8 +150,7 @@ class AVPlayer {
|
|||||||
|
|
||||||
async queryFile(displayName: string): Promise<mediaLibrary.FileAsset> {
|
async queryFile(displayName: string): Promise<mediaLibrary.FileAsset> {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
const context = AppStorage.get<common.UIAbilityContext>('context')
|
const mediaLib = mediaLibrary.getMediaLibrary(this.context);
|
||||||
const mediaLib = mediaLibrary.getMediaLibrary(context);
|
|
||||||
let fileResult = await mediaLib.getFileAssets({
|
let fileResult = await mediaLib.getFileAssets({
|
||||||
selections: `media_type=? AND display_name = ?`,
|
selections: `media_type=? AND display_name = ?`,
|
||||||
selectionArgs: [`${mediaLibrary.MediaType.AUDIO}`, displayName],
|
selectionArgs: [`${mediaLibrary.MediaType.AUDIO}`, displayName],
|
||||||
@ -197,14 +198,14 @@ class AVPlayer {
|
|||||||
case 'prepared': // prepare调用成功后上报该状态机
|
case 'prepared': // prepare调用成功后上报该状态机
|
||||||
console.info(TAG, '播放资源播放')
|
console.info(TAG, '播放资源播放')
|
||||||
this.avPlayer!.play();
|
this.avPlayer!.play();
|
||||||
// this.voiceStatus = 'playing'
|
// this.voiceStatus = 'playing'
|
||||||
break;
|
break;
|
||||||
case 'playing': // play成功调用后触发该状态机上报
|
case 'playing': // play成功调用后触发该状态机上报
|
||||||
break;
|
break;
|
||||||
case 'paused': // pause成功调用后触发该状态机上报
|
case 'paused': // pause成功调用后触发该状态机上报
|
||||||
break;
|
break;
|
||||||
case 'completed': // 播放结束后触发该状态机上报
|
case 'completed': // 播放结束后触发该状态机上报
|
||||||
// this.voiceStatus = 'completed'
|
// this.voiceStatus = 'completed'
|
||||||
this.avPlayer!.stop(); //调用播放结束接口
|
this.avPlayer!.stop(); //调用播放结束接口
|
||||||
break;
|
break;
|
||||||
case 'stopped': // stop接口成功调用后触发该状态机上报
|
case 'stopped': // stop接口成功调用后触发该状态机上报
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user