Skip to content

Commit

Permalink
Guided navigation (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
chocolatkey authored Sep 12, 2024
1 parent 7117407 commit bb3a594
Show file tree
Hide file tree
Showing 10 changed files with 655 additions and 2 deletions.
1 change: 1 addition & 0 deletions navigator-html-injectables/src/modules/setup/Setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export abstract class Setup extends Module {
cancelable: ev.cancelable
});
if(ev.currentTarget) ev.currentTarget.dispatchEvent(evt)
else if(ev.target) ev.target.dispatchEvent(evt)
else wnd.dispatchEvent(evt);
break;
}
Expand Down
136 changes: 136 additions & 0 deletions navigator/src/audio/engine/AudioEngine.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import { Locator } from '@readium/shared/src/publication/Locator';
import { Publication } from '@readium/shared/src/publication/Publication';

/**
* Initial state of the audio engine playback.
*/
export interface PlaybackState {
/**
* The current time of the audio resource.
*/
currentTime: number;

/**
* The duration of the audio resource.
*/
duration: number;

/**
* The volume of the audio resource.
*/
volume: number;
}

/**
* Playback interface for an audio engine state
* @state The initial [PlaybackState].
* @playWhenReady Indicates if the navigator should play as soon as the state is Ready.
* @index Index of the reading order item currently being played.
* @offset Position of the playback in the current item.
* @buffered Position in the current item until which the content is buffered.
*
*/
export interface Playback {
state: PlaybackState;
playWhenReady: boolean;
index: number;
offset?: number;
buffered?: number;
}

/**
* An audio engine that plays audio resources from a publication.
* @playback - The current [Playback] state.
*/
export interface AudioEngine {
/**
* The current playback state.
*/
playback: Playback;

/**
* Plays the audio resource at the given locator.
*/
playLocator(publication: Publication, locator: Locator): Promise<void>;

/**
* Adds an event listener to the audio engine.
* @param event The event name to listen.
* @param callback Callback function to be called when the event is triggered.
*/
on(event: string, callback: (data: any) => void): void;

/**
* Removes an event listener from the audio engine.
* @param event The event name to remove the listener.
* @param callback Callback function to be removed.
*/
off(event: string, callback: (data: any) => void): void;

/**
* Loads the audio resource at the given URL.
* @param url The URL of the audio resource.
*/
loadAudio(url: string): void;

/**
* Plays the current audio resource.
*/
play(): void;

/**
* Pauses the currently playing audio resource.
*/
pause(): void;

/**
* Stops the currently playing audio resource.
*/
stop(): void;

/**
* Skips [duration] either forward or backward if [duration] is negative.
*/
skip(duration: number): void;

/**
* Returns the duration of the audio resource.
*/
duration(): number;

/**
* Returns whether the audio resource is currently playing.
*/
isPlaying(): boolean;

/**
* Returns whether the audio resource is currently paused.
*/
isPaused(): boolean;

/**
* Returns whether the audio resource is currently stopped.
*/
isStopped(): boolean;

/**
* Returns whether the audio resource is currently loading.
*/
isLoading(): boolean;

/**
* Returns whether the audio resource is currently loaded.
*/
isLoaded(): boolean;

/**
* Returns whether the audio resource is currently ended.
*/
isEnded(): boolean;

/**
* Returns whether the audio resource is currently muted.
*/
isMuted(): boolean;

}
Loading

0 comments on commit bb3a594

Please sign in to comment.