Showing
2 changed files
with
35 additions
and
22 deletions
| @@ -3,7 +3,8 @@ import { MultiPictureDetailViewModel } from '../viewmodel/MultiPictureDetailView | @@ -3,7 +3,8 @@ import { MultiPictureDetailViewModel } from '../viewmodel/MultiPictureDetailView | ||
| 3 | import { ContentDetailDTO } from 'wdBean'; | 3 | import { ContentDetailDTO } from 'wdBean'; |
| 4 | import media from '@ohos.multimedia.media'; | 4 | import media from '@ohos.multimedia.media'; |
| 5 | import { OperRowListView } from './view/OperRowListView'; | 5 | import { OperRowListView } from './view/OperRowListView'; |
| 6 | -import { WDPlayerController } from 'wdPlayer'; | 6 | +import { WDPlayerController } from 'wdPlayer/Index'; |
| 7 | + | ||
| 7 | const TAG = 'AudioDetailComponent' | 8 | const TAG = 'AudioDetailComponent' |
| 8 | interface Arr{ | 9 | interface Arr{ |
| 9 | image:string, | 10 | image:string, |
| @@ -15,7 +16,8 @@ export struct AudioDetailComponent { | @@ -15,7 +16,8 @@ export struct AudioDetailComponent { | ||
| 15 | private relId: string = '' | 16 | private relId: string = '' |
| 16 | private contentId: string = '' | 17 | private contentId: string = '' |
| 17 | private relType: string = '' | 18 | private relType: string = '' |
| 18 | - private playerController: WDPlayerController = new WDPlayerController(); | 19 | + private avPlayer?: media.AVPlayer; |
| 20 | + @State playerController: WDPlayerController = new WDPlayerController(); | ||
| 19 | 21 | ||
| 20 | private arr:Arr[]=[ | 22 | private arr:Arr[]=[ |
| 21 | {image:'clock',title:'定时'}, | 23 | {image:'clock',title:'定时'}, |
| @@ -26,24 +28,24 @@ export struct AudioDetailComponent { | @@ -26,24 +28,24 @@ export struct AudioDetailComponent { | ||
| 26 | @State contentDetailData: ContentDetailDTO[] = [] as ContentDetailDTO[]//详情 | 28 | @State contentDetailData: ContentDetailDTO[] = [] as ContentDetailDTO[]//详情 |
| 27 | @State coverImage:string = '' //封面图 | 29 | @State coverImage:string = '' //封面图 |
| 28 | @State newsTitle:string = '' //标题 | 30 | @State newsTitle:string = '' //标题 |
| 29 | - @State duration:number = 0 //时长 | ||
| 30 | @State audioUrl:string = '' //音频路径 | 31 | @State audioUrl:string = '' //音频路径 |
| 32 | + @State duration:number = 0 //时长 | ||
| 31 | @State outSetValueOne:number = 40 //播放进度 | 33 | @State outSetValueOne:number = 40 //播放进度 |
| 32 | 34 | ||
| 33 | - @State @Watch('onIsPlayChanged')isPlay: boolean = true | ||
| 34 | - onIsPlayChanged(){ | ||
| 35 | - if(this.isPlay){ | ||
| 36 | - console.log('监听播放') | ||
| 37 | - // this.avPlayer.play() | ||
| 38 | - }else{ | ||
| 39 | - console.log('监听暂停') | ||
| 40 | - // this.avPlayer.pause() | ||
| 41 | - } | ||
| 42 | - } | ||
| 43 | - | 35 | + @State isPlay: boolean = false |
| 44 | async aboutToAppear() { | 36 | async aboutToAppear() { |
| 45 | await this.getContentDetailData() | 37 | await this.getContentDetailData() |
| 46 | this.playerController.firstPlay(this.audioUrl); | 38 | this.playerController.firstPlay(this.audioUrl); |
| 39 | + this.playerController.onCanplay = () => { | ||
| 40 | + this.playerController.play() | ||
| 41 | + this.isPlay = true | ||
| 42 | + } | ||
| 43 | + this.playerController.onTimeUpdate = (nowSeconds, totalSeconds) =>{ | ||
| 44 | + console.log('现在时间',nowSeconds) | ||
| 45 | + console.log('总时间',totalSeconds) | ||
| 46 | + this.outSetValueOne = nowSeconds | ||
| 47 | + this.duration = totalSeconds | ||
| 48 | + } | ||
| 47 | } | 49 | } |
| 48 | build() { | 50 | build() { |
| 49 | Row() { | 51 | Row() { |
| @@ -94,10 +96,17 @@ export struct AudioDetailComponent { | @@ -94,10 +96,17 @@ export struct AudioDetailComponent { | ||
| 94 | Column(){ | 96 | Column(){ |
| 95 | // 进度条 | 97 | // 进度条 |
| 96 | Row(){ | 98 | Row(){ |
| 97 | - Progress({ value: this.outSetValueOne, type: ProgressType.Linear }) | ||
| 98 | - .width('100%') | ||
| 99 | - .color('#ED2800') | ||
| 100 | - .backgroundColor('rgba(0,0,0,0.5)') | 99 | + Slider({ |
| 100 | + value: this.outSetValueOne, | ||
| 101 | + step: 1 | ||
| 102 | + }) | ||
| 103 | + .showTips(true) | ||
| 104 | + .trackColor('rgba(0,0,0,0.5)') | ||
| 105 | + .selectedColor('#ED2800') | ||
| 106 | + .onChange((value: number, mode: SliderChangeMode) => { | ||
| 107 | + console.log('滑块长度',value) | ||
| 108 | + this.playerController?.setSeekTime(value, mode); | ||
| 109 | + }) | ||
| 101 | } | 110 | } |
| 102 | .width('100%') | 111 | .width('100%') |
| 103 | .padding({left:24,right:24}) | 112 | .padding({left:24,right:24}) |
| @@ -126,6 +135,14 @@ export struct AudioDetailComponent { | @@ -126,6 +135,14 @@ export struct AudioDetailComponent { | ||
| 126 | .padding(28) | 135 | .padding(28) |
| 127 | .backgroundColor('#4D5258') | 136 | .backgroundColor('#4D5258') |
| 128 | .borderRadius(50) | 137 | .borderRadius(50) |
| 138 | + .onClick(()=>{ | ||
| 139 | + if(this.isPlay){ | ||
| 140 | + this.playerController.pause() | ||
| 141 | + }else{ | ||
| 142 | + this.playerController.play() | ||
| 143 | + } | ||
| 144 | + this.isPlay = !this.isPlay | ||
| 145 | + }) | ||
| 129 | Image($r('app.media.fastForward_close')) | 146 | Image($r('app.media.fastForward_close')) |
| 130 | .width(24) | 147 | .width(24) |
| 131 | .height(24) | 148 | .height(24) |
| @@ -151,7 +168,6 @@ export struct AudioDetailComponent { | @@ -151,7 +168,6 @@ export struct AudioDetailComponent { | ||
| 151 | } | 168 | } |
| 152 | 169 | ||
| 153 | } | 170 | } |
| 154 | - | ||
| 155 | private async getContentDetailData() { | 171 | private async getContentDetailData() { |
| 156 | try { | 172 | try { |
| 157 | let data = await MultiPictureDetailViewModel.getDetailData(this.relId, this.contentId, this.relType) | 173 | let data = await MultiPictureDetailViewModel.getDetailData(this.relId, this.contentId, this.relType) |
| @@ -29,8 +29,5 @@ struct AudioDetail { | @@ -29,8 +29,5 @@ struct AudioDetail { | ||
| 29 | this.relId = params?.extra?.relId || ''; | 29 | this.relId = params?.extra?.relId || ''; |
| 30 | this.relType = params?.extra?.relType || ''; | 30 | this.relType = params?.extra?.relType || ''; |
| 31 | this.contentId = params?.contentID || ''; | 31 | this.contentId = params?.contentID || ''; |
| 32 | - Logger.info(TAG, 'aboutToAppear'); | ||
| 33 | - Logger.info(TAG, 'params', JSON.stringify(params)); | ||
| 34 | - console.log('参数',JSON.stringify(par)) | ||
| 35 | } | 32 | } |
| 36 | } | 33 | } |
-
Please register or login to post a comment