diff --git a/demo/src/main-view-model.ts b/demo/src/main-view-model.ts index 07f5eb1..b550118 100644 --- a/demo/src/main-view-model.ts +++ b/demo/src/main-view-model.ts @@ -24,6 +24,9 @@ export class HelloWorldModel extends Observable implements PlaybackEventListener public async loadAndSetupPlaylist() { const playlistUID = 'UID_12345'; + + this.player.setUseNavigationActions(true); + if (this.player.getCurrentPlaylistUID() === playlistUID) { console.log(`Player already has playlist: ${this.player.getCurrentPlaylistUID()}`); diff --git a/src/audioplayer-common.ts b/src/audioplayer-common.ts index 4684a6d..059cbe6 100644 --- a/src/audioplayer-common.ts +++ b/src/audioplayer-common.ts @@ -108,6 +108,22 @@ export class CommonAudioPlayer extends Observable { throw new Error('Not implemented'); } + public async setUseNavigationActions(value:boolean){ + throw new Error('Not implemented'); + } + + public async setUseNavigationActionsInCompactView(value:boolean){ + throw new Error('Not implemented'); + } + + public async setUsePlayPauseActions(value:boolean){ + throw new Error('Not implemented'); + } + + public async setUseStopAction(value:boolean){ + throw new Error('Not implemented'); + } + /** * Set playbackRate */ diff --git a/src/audioplayer.android.ts b/src/audioplayer.android.ts index 93e46ff..63d63ee 100644 --- a/src/audioplayer.android.ts +++ b/src/audioplayer.android.ts @@ -291,6 +291,22 @@ export class TNSAudioPlayer extends CommonAudioPlayer { } } + public async setUseNavigationActions(value:boolean){ + (await this.mediaService).setUseNavigationActions(value); + } + + public async setUseNavigationActionsInCompactView(value:boolean){ + (await this.mediaService).setUseNavigationActionsInCompactView(value); + } + + public async setUsePlayPauseActions(value:boolean){ + (await this.mediaService).setUsePlayPauseActions(value); + } + + public async setUseStopAction(value:boolean){ + (await this.mediaService).setUseStopAction(value); + } + public async setRate(rate: number) { if (typeof rate === 'number' && !Number.isNaN(rate)) { this._playbackRate = rate; diff --git a/src/media-service.android.ts b/src/media-service.android.ts index f22d7d3..31ebe67 100644 --- a/src/media-service.android.ts +++ b/src/media-service.android.ts @@ -11,6 +11,10 @@ const MEDIA_SERVICE_NAME = 'TNS-MediaService-1'; const DEFAULT_PLAYBACK_RATE = 1; const DEFAULT_INTENT_CODE = 1337; const DEFAULT_SEEK_LENGTH = 15; +const DEFAULT_USE_NAVIGATION_ACTIONS = false; +const DEFAULT_USE_NAVIGATION_ACTIONS_IN_COMPACT_VIEW = true; +const DEFAULT_USE_PLAY_PAUSE_ACTIONS = true; +const DEFAULT_USE_STOP_ACTION = false; export namespace dk { export namespace nota { @@ -19,6 +23,7 @@ export namespace dk { @JavaProxy('dk.nota.MediaService') export class MediaService extends android.app.Service { private _cls: string; + private get cls() { if (!this._cls) { this._cls = `MediaService<${++instance}>`; @@ -54,6 +59,11 @@ export namespace dk { private _intentReqCode = DEFAULT_INTENT_CODE; private _timeChangeInterval: number; + private _useNavigationActions: boolean; + private _useNavigationActionsInCompactView: boolean; + private _usePlayPauseActions: boolean; + private _useStopAction: boolean; + private _albumArts?: Map>; private get albumArts() { if (!this._albumArts) { @@ -499,10 +509,6 @@ export namespace dk { this._playerNotificationManager.setPlayer(this.exoPlayer); this._playerNotificationManager.setVisibility(androidx.core.app.NotificationCompat.VISIBILITY_PUBLIC); - this._playerNotificationManager.setUseNavigationActionsInCompactView(true); - this._playerNotificationManager.setUsePlayPauseActions(true); - this._playerNotificationManager.setUseNavigationActions(false); - this._playerNotificationManager.setUseStopAction(false); const notificationIcon = nsUtils.ad.resources.getDrawableId('tns_audioplayer_small_icon'); if (notificationIcon) { this._playerNotificationManager.setSmallIcon(notificationIcon); @@ -512,6 +518,12 @@ export namespace dk { this.setRate(this._rate); this.setSeekIntervalSeconds(this._seekIntervalSeconds); + + this._playerNotificationManager.setUseNavigationActionsInCompactView(this._useNavigationActionsInCompactView??DEFAULT_USE_NAVIGATION_ACTIONS_IN_COMPACT_VIEW); + this._playerNotificationManager.setUsePlayPauseActions(this._usePlayPauseActions??DEFAULT_USE_PLAY_PAUSE_ACTIONS); + this._playerNotificationManager.setUseNavigationActions(this._useNavigationActions??DEFAULT_USE_NAVIGATION_ACTIONS); + this._playerNotificationManager.setUseStopAction(this._useStopAction??DEFAULT_USE_STOP_ACTION); + this._mediaSessionConnector?.setPlayer(this.exoPlayer); this.exoPlayer.prepare(concatenatedSource); } @@ -533,6 +545,22 @@ export namespace dk { this._playerNotificationManager.setRewindIncrementMs(seekMs); } + public setUseNavigationActions(value:boolean){ + this._useNavigationActions = value; + } + + public setUseNavigationActionsInCompactView(value:boolean){ + this._useNavigationActionsInCompactView = value; + } + + public setUsePlayPauseActions(value:boolean){ + this._usePlayPauseActions = value; + } + + public setUseStopAction(value:boolean){ + this._useStopAction = value; + } + public setRate(rate: number) { if (trace.isEnabled()) { trace.write(`${this.cls}.setRate(${rate})`, notaAudioCategory); diff --git a/src/media-service.d.ts b/src/media-service.d.ts index 5821c07..d85c7c4 100644 --- a/src/media-service.d.ts +++ b/src/media-service.d.ts @@ -8,6 +8,10 @@ declare namespace dk { public setRate(rate: number): void; public getRate(): number; public setOwner(owner: any): void; + public setUseNavigationActions(value:boolean); + public setUseNavigationActionsInCompactView(value:boolean); + public setUsePlayPauseActions(value:boolean); + public setUseStopAction(value:boolean); public isPlaying(): boolean; public play(): void;