diff --git a/VideoPlayerSample/MediaService/src/main/ets/controller/AvPlayerController.ets b/VideoPlayerSample/MediaService/src/main/ets/controller/AvPlayerController.ets index 3e0727e2324da5cbf3a99fb75716c7fe018f6c0b..38fc91a3b0c1036b84a6913f55dc02efd53c3dc3 100644 --- a/VideoPlayerSample/MediaService/src/main/ets/controller/AvPlayerController.ets +++ b/VideoPlayerSample/MediaService/src/main/ets/controller/AvPlayerController.ets @@ -138,12 +138,22 @@ export class AvPlayerController { case audio.InterruptHint.INTERRUPT_HINT_PAUSE: // This branch indicates that the system has paused the audio stream (temporarily lost focus). In order to keep the state consistent, the application needs to switch to the audio paused state. // Temporary loss of focus: after other audio streams release the audio focus, this audio stream will receive the audio interruption event corresponding to resume, and then it can continue playing by itself. + /** + * Update play status + * @param isPlay is it playing + * @returns void + */ this.updateIsPlay(false); this.pauseVideo(); break; case audio.InterruptHint.INTERRUPT_HINT_STOP: // This branch indicates that the system has stopped the audio stream (permanently lost focus). In order to keep the state consistent, the application needs to switch to the audio pause state. // Permanent loss of focus: no audio interruption events will be received in the future. If you want to resume playing, you need the user to trigger it actively. + /** + * Update play status + * @param isPlay is it playing + * @returns void + */ this.updateIsPlay(false); this.pauseVideo(); break; diff --git a/VideoPlayerSample/MediaService/src/main/ets/controller/AvSessionController.ets b/VideoPlayerSample/MediaService/src/main/ets/controller/AvSessionController.ets index 587fc0389df86ed78d4960409d6d8c251f3fb648..54f6bfe12552a15e114875cb3dcecd3dfcd5aa05 100644 --- a/VideoPlayerSample/MediaService/src/main/ets/controller/AvSessionController.ets +++ b/VideoPlayerSample/MediaService/src/main/ets/controller/AvSessionController.ets @@ -26,7 +26,7 @@ const TAG = 'AvSessionController'; export class AvSessionController { private static instance: AvSessionController | null; private context: common.UIAbilityContext | undefined = undefined; - private avSession: avSession.AVSession | undefined = undefined; + private avSession?: avSession.AVSession; private avSessionMetadata: avSession.AVMetadata | undefined = undefined; constructor() { diff --git a/VideoPlayerSample/MediaService/src/main/ets/controller/AvSessionController1.ets b/VideoPlayerSample/MediaService/src/main/ets/controller/AvSessionController1.ets index 172eaabd03baa0e68949a3bd54eea0d394829719..940dc40a18c9915eb4b649339ddb3970da2d6253 100644 --- a/VideoPlayerSample/MediaService/src/main/ets/controller/AvSessionController1.ets +++ b/VideoPlayerSample/MediaService/src/main/ets/controller/AvSessionController1.ets @@ -20,7 +20,7 @@ import { avSession } from '@kit.AVSessionKit'; const TAG = 'AvSessionController'; export class AvSessionController { - private avSession: avSession.AVSession | undefined = undefined; + private avSession?: avSession.AVSession; private context: common.UIAbilityContext | undefined = undefined; public initAvSession() { this.context = AppStorage.get('context'); diff --git a/VideoPlayerSample/entry/src/main/ets/view/AVPlayer.ets b/VideoPlayerSample/entry/src/main/ets/view/AVPlayer.ets index 79faaa81a8a788b0d19574a2fbd6d663a9f039c2..67c177f87935bca1a056693e5e47495ddf8db251 100644 --- a/VideoPlayerSample/entry/src/main/ets/view/AVPlayer.ets +++ b/VideoPlayerSample/entry/src/main/ets/view/AVPlayer.ets @@ -318,8 +318,7 @@ export struct VideoPlayer { // On the right side of the screen relative to the X-axis coordinate in the upper left corner of the application window, adjust the brightness. this.visible = true; let curBrightness = this.screenBrightness - this.getUIContext().vp2px(event.offsetY) / this.getUIContext().vp2px(this.screenHeight); - curBrightness = curBrightness >= 1.0 ? 1.0 : curBrightness; - curBrightness = curBrightness <= 0.0 ? 0.0 : curBrightness; + curBrightness = Math.max(0, Math.min(1.0, curBrightness)); this.screenBrightness = curBrightness; hilog.info(0x0000, 'AVPlayer', `this brightness is: ` + this.screenBrightness); @@ -560,7 +559,7 @@ export struct VideoPlayer { } // 前台进度条变化接口 - // [Start slider] + // [Start slider1] sliderOnchange(seconds: number, mode: SliderChangeMode) { let seekTime: number = seconds * this.avPlayerController.duration / this.avPlayerController.durationTime; this.currentStringTime = secondToTime(Math.floor(seekTime / CommonConstants.SECOND_TO_MS)); @@ -571,27 +570,31 @@ export struct VideoPlayer { case SliderChangeMode.Click: break; case SliderChangeMode.Moving: - // [StartExclude slider] + // [StartExclude slider1] this.isSliderDragging = true; this.isTimeDisplay = 1; this.trackThicknessSize = CommonConstants.TRACK_SIZE_MAX; this.sliderStyle = SliderStyle.OutSet; - // [EndExclude slider] + // [EndExclude slider1] break; case SliderChangeMode.End: - this.avPlayerController.seek(seekTime); // Call the seek method of AVPlayer to control the playback progress. - // [StartExclude slider] + try { + this.avPlayerController.seek(seekTime); // Call the seek method of AVPlayer to control the playback progress. + } catch (err) { + Logger.error(TAG, `AVPlsyer seek failed, err.code:${err.code}, err.message:${err.message}`); + } + // [StartExclude slider1] this.isTimeDisplay = 0; this.trackThicknessSize = CommonConstants.TRACK_SIZE_MIN; this.sliderStyle = SliderStyle.NONE; this.isSliderDragging = false; - // [EndExclude slider] + // [EndExclude slider1] break; default: break; } } - // [End slider] + // [End slider1] async iconOnclick() { if (this.avPlayerController.isPlaying) {