Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Added customization for notification buttons (issue #12) #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions demo/src/main-view-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()}`);

Expand Down
16 changes: 16 additions & 0 deletions src/audioplayer-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
16 changes: 16 additions & 0 deletions src/audioplayer.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
36 changes: 32 additions & 4 deletions src/media-service.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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}>`;
Expand Down Expand Up @@ -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<string, Promise<ImageSource>>;
private get albumArts() {
if (!this._albumArts) {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/media-service.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down