@javascriptcommon/react-native-track-player 4.1.7 → 4.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/android/src/main/java/com/doublesymmetry/trackplayer/module/MusicModule.kt +2 -0
  2. package/android/src/main/java/com/doublesymmetry/trackplayer/service/MusicService.kt +38 -32
  3. package/android/src/main/java/com/doublesymmetry/trackplayer/utils/AutoConnectionDetector.kt +97 -0
  4. package/package.json +1 -2
  5. package/lib/src/TrackPlayerModule.web.d.ts +0 -2
  6. package/lib/src/TrackPlayerModule.web.js +0 -2
  7. package/lib/src/resolveAssetSource.web.d.ts +0 -2
  8. package/lib/src/resolveAssetSource.web.js +0 -8
  9. package/lib/web/TrackPlayer/Player.d.ts +0 -40
  10. package/lib/web/TrackPlayer/Player.js +0 -188
  11. package/lib/web/TrackPlayer/PlaylistPlayer.d.ts +0 -31
  12. package/lib/web/TrackPlayer/PlaylistPlayer.js +0 -181
  13. package/lib/web/TrackPlayer/RepeatMode.d.ts +0 -5
  14. package/lib/web/TrackPlayer/RepeatMode.js +0 -6
  15. package/lib/web/TrackPlayer/SetupNotCalledError.d.ts +0 -3
  16. package/lib/web/TrackPlayer/SetupNotCalledError.js +0 -5
  17. package/lib/web/TrackPlayer/index.d.ts +0 -3
  18. package/lib/web/TrackPlayer/index.js +0 -3
  19. package/lib/web/TrackPlayerModule.d.ts +0 -63
  20. package/lib/web/TrackPlayerModule.js +0 -153
  21. package/lib/web/index.d.ts +0 -3
  22. package/lib/web/index.js +0 -3
  23. package/src/TrackPlayerModule.web.ts +0 -2
  24. package/src/resolveAssetSource.web.ts +0 -10
  25. package/web/TrackPlayer/Player.ts +0 -201
  26. package/web/TrackPlayer/PlaylistPlayer.ts +0 -215
  27. package/web/TrackPlayer/RepeatMode.ts +0 -6
  28. package/web/TrackPlayer/SetupNotCalledError.ts +0 -5
  29. package/web/TrackPlayer/index.ts +0 -3
  30. package/web/TrackPlayerModule.ts +0 -181
  31. package/web/index.ts +0 -4
@@ -1,6 +0,0 @@
1
-
2
- export enum RepeatMode {
3
- Off = 'REPEAT_OFF',
4
- Track = 'REPEAT_TRACK',
5
- Playlist = 'REPEAT_PLAYLIST',
6
- }
@@ -1,5 +0,0 @@
1
- export class SetupNotCalledError extends Error {
2
- constructor() {
3
- super('You must call `setupPlayer` prior to interacting with the player.');
4
- }
5
- }
@@ -1,3 +0,0 @@
1
- export * from './Player';
2
- export * from './PlaylistPlayer';
3
- export * from './RepeatMode';
@@ -1,181 +0,0 @@
1
- import { DeviceEventEmitter } from 'react-native';
2
-
3
- import { Event, PlaybackState, State } from '../src';
4
- import type { Track, UpdateOptions } from '../src';
5
- import { PlaylistPlayer, RepeatMode } from './TrackPlayer';
6
- import { SetupNotCalledError } from './TrackPlayer/SetupNotCalledError';
7
-
8
- export class TrackPlayerModule extends PlaylistPlayer {
9
- protected emitter = DeviceEventEmitter;
10
- protected progressUpdateEventInterval: any;
11
-
12
- // Capabilities
13
- public readonly CAPABILITY_PLAY = 'CAPABILITY_PLAY';
14
- public readonly CAPABILITY_PLAY_FROM_ID = 'CAPABILITY_PLAY_FROM_ID';
15
- public readonly CAPABILITY_PLAY_FROM_SEARCH = 'CAPABILITY_PLAY_FROM_SEARCH';
16
- public readonly CAPABILITY_PAUSE = 'CAPABILITY_PAUSE';
17
- public readonly CAPABILITY_STOP = 'CAPABILITY_STOP';
18
- public readonly CAPABILITY_SEEK_TO = 'CAPABILITY_SEEK_TO';
19
- public readonly CAPABILITY_SKIP = 'CAPABILITY_SKIP';
20
- public readonly CAPABILITY_SKIP_TO_NEXT = 'CAPABILITY_SKIP_TO_NEXT';
21
- public readonly CAPABILITY_SKIP_TO_PREVIOUS = 'CAPABILITY_SKIP_TO_PREVIOUS';
22
- public readonly CAPABILITY_JUMP_FORWARD = 'CAPABILITY_JUMP_FORWARD';
23
- public readonly CAPABILITY_JUMP_BACKWARD = 'CAPABILITY_JUMP_BACKWARD';
24
- public readonly CAPABILITY_SET_RATING = 'CAPABILITY_SET_RATING';
25
- public readonly CAPABILITY_LIKE = 'CAPABILITY_LIKE';
26
- public readonly CAPABILITY_DISLIKE = 'CAPABILITY_DISLIKE';
27
- public readonly CAPABILITY_BOOKMARK = 'CAPABILITY_BOOKMARK';
28
-
29
- // States
30
- public readonly STATE_NONE = 'STATE_NONE';
31
- public readonly STATE_READY = 'STATE_READY';
32
- public readonly STATE_PLAYING = 'STATE_PLAYING';
33
- public readonly STATE_PAUSED = 'STATE_PAUSED';
34
- public readonly STATE_STOPPED = 'STATE_STOPPED';
35
- public readonly STATE_BUFFERING = 'STATE_BUFFERING';
36
- public readonly STATE_CONNECTING = 'STATE_CONNECTING';
37
-
38
- // Rating Types
39
- public readonly RATING_HEART = 'RATING_HEART';
40
- public readonly RATING_THUMBS_UP_DOWN = 'RATING_THUMBS_UP_DOWN';
41
- public readonly RATING_3_STARS = 'RATING_3_STARS';
42
- public readonly RATING_4_STARS = 'RATING_4_STARS';
43
- public readonly RATING_5_STARS = 'RATING_5_STARS';
44
- public readonly RATING_PERCENTAGE = 'RATING_PERCENTAGE';
45
-
46
- // Repeat Modes
47
- public readonly REPEAT_OFF = RepeatMode.Off;
48
- public readonly REPEAT_TRACK = RepeatMode.Track;
49
- public readonly REPEAT_QUEUE = RepeatMode.Playlist;
50
-
51
- // Pitch Algorithms
52
- public readonly PITCH_ALGORITHM_LINEAR = 'PITCH_ALGORITHM_LINEAR';
53
- public readonly PITCH_ALGORITHM_MUSIC = 'PITCH_ALGORITHM_MUSIC';
54
- public readonly PITCH_ALGORITHM_VOICE = 'PITCH_ALGORITHM_VOICE';
55
-
56
- // observe and emit state changes
57
- public get state(): PlaybackState {
58
- return super.state;
59
- }
60
- public set state(newState: PlaybackState) {
61
- super.state = newState;
62
- this.emitter.emit(Event.PlaybackState, newState);
63
- }
64
-
65
- public async updateOptions(options: UpdateOptions) {
66
- this.setupProgressUpdates(options.progressUpdateEventInterval);
67
- }
68
-
69
- protected setupProgressUpdates(interval?: number) {
70
- // clear and reset interval
71
- this.clearUpdateEventInterval();
72
- if (interval) {
73
- this.clearUpdateEventInterval()
74
- this.progressUpdateEventInterval = setInterval(
75
- async () => {
76
- if (this.state.state === State.Playing) {
77
- const progress = await this.getProgress()
78
- this.emitter.emit(Event.PlaybackProgressUpdated, {
79
- ...progress,
80
- track: this.currentIndex,
81
- });
82
- }
83
- },
84
- interval * 1000,
85
- )
86
- }
87
- }
88
-
89
- protected clearUpdateEventInterval() {
90
- if (this.progressUpdateEventInterval) {
91
- clearInterval(this.progressUpdateEventInterval);
92
- }
93
- }
94
-
95
- protected async onTrackEnded() {
96
- const position = this.element!.currentTime;
97
- await super.onTrackEnded();
98
-
99
- this.emitter.emit(Event.PlaybackTrackChanged, {
100
- track: this.lastIndex,
101
- position,
102
- nextTrack: this.currentIndex,
103
- });
104
- }
105
-
106
- protected async onPlaylistEnded() {
107
- await super.onPlaylistEnded();
108
- this.emitter.emit(Event.PlaybackQueueEnded, {
109
- track: this.currentIndex,
110
- position: this.element!.currentTime,
111
- });
112
- }
113
-
114
- public get playWhenReady(): boolean {
115
- return super.playWhenReady;
116
- }
117
-
118
- public set playWhenReady(pwr: boolean) {
119
- const didChange = pwr !== this._playWhenReady;
120
- super.playWhenReady = pwr;
121
-
122
- if (didChange) {
123
- this.emitter.emit(Event.PlaybackPlayWhenReadyChanged, { playWhenReady: this._playWhenReady });
124
- }
125
- }
126
-
127
- public getPlayWhenReady(): boolean {
128
- return this.playWhenReady;
129
- }
130
-
131
- public setPlayWhenReady(pwr: boolean): boolean {
132
- this.playWhenReady = pwr;
133
- return this.playWhenReady;
134
- }
135
-
136
- public async load(track: Track) {
137
- if (!this.element) throw new SetupNotCalledError();
138
- const lastTrack = this.current;
139
- const lastPosition = this.element.currentTime;
140
- await super.load(track);
141
-
142
- this.emitter.emit(Event.PlaybackActiveTrackChanged, {
143
- lastTrack,
144
- lastPosition,
145
- lastIndex: this.lastIndex,
146
- index: this.currentIndex,
147
- track,
148
- });
149
- }
150
-
151
- public getQueue(): Track[] {
152
- return this.playlist;
153
- }
154
-
155
- public async setQueue(queue: Track[]) {
156
- await this.stop();
157
- this.playlist = queue;
158
- }
159
-
160
- public getActiveTrack(): Track | undefined {
161
- return this.current;
162
- }
163
-
164
- public getActiveTrackIndex(): number | undefined {
165
- // per the existing spec, this should throw if setup hasn't been called
166
- if (!this.element || !this.player) throw new SetupNotCalledError();
167
- return this.currentIndex;
168
- }
169
-
170
- /**
171
- * @deprecated
172
- * @returns State
173
- */
174
- public getState(): State {
175
- return this.state.state;
176
- }
177
-
178
- public getPlaybackState(): PlaybackState {
179
- return this.state;
180
- }
181
- };
package/web/index.ts DELETED
@@ -1,4 +0,0 @@
1
- import {TrackPlayerModule} from './TrackPlayerModule';
2
-
3
- const module = new TrackPlayerModule();
4
- export default module;