react-native-nitro-player 0.3.0-alpha.5 → 0.3.0-alpha.6
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.
- package/README.md +1 -1
- package/lib/hooks/index.d.ts +6 -0
- package/lib/hooks/index.js +6 -0
- package/lib/hooks/useAndroidAutoConnection.d.ts +13 -0
- package/lib/hooks/useAndroidAutoConnection.js +26 -0
- package/lib/hooks/useAudioDevices.d.ts +26 -0
- package/lib/hooks/useAudioDevices.js +55 -0
- package/lib/hooks/useOnChangeTrack.d.ts +9 -0
- package/lib/hooks/useOnChangeTrack.js +17 -0
- package/lib/hooks/useOnPlaybackProgressChange.d.ts +9 -0
- package/lib/hooks/useOnPlaybackProgressChange.js +19 -0
- package/lib/hooks/useOnPlaybackStateChange.d.ts +9 -0
- package/lib/hooks/useOnPlaybackStateChange.js +17 -0
- package/lib/hooks/useOnSeek.d.ts +8 -0
- package/lib/hooks/useOnSeek.js +17 -0
- package/lib/index.d.ts +15 -0
- package/lib/index.js +24 -0
- package/lib/specs/AndroidAutoMediaLibrary.nitro.d.ts +21 -0
- package/lib/specs/AndroidAutoMediaLibrary.nitro.js +1 -0
- package/lib/specs/AudioDevices.nitro.d.ts +24 -0
- package/lib/specs/AudioDevices.nitro.js +1 -0
- package/lib/specs/AudioRoutePicker.nitro.d.ts +10 -0
- package/lib/specs/AudioRoutePicker.nitro.js +1 -0
- package/lib/specs/TrackPlayer.nitro.d.ts +41 -0
- package/lib/specs/TrackPlayer.nitro.js +1 -0
- package/lib/types/AndroidAutoMediaLibrary.d.ts +44 -0
- package/lib/types/AndroidAutoMediaLibrary.js +1 -0
- package/lib/types/PlayerQueue.d.ts +32 -0
- package/lib/types/PlayerQueue.js +1 -0
- package/lib/utils/androidAutoMediaLibrary.d.ts +47 -0
- package/lib/utils/androidAutoMediaLibrary.js +62 -0
- package/package.json +5 -8
package/README.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Refer Root readme
|
|
1
|
+
Refer Root readme
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { useOnChangeTrack } from './useOnChangeTrack';
|
|
2
|
+
export { useOnPlaybackStateChange } from './useOnPlaybackStateChange';
|
|
3
|
+
export { useOnSeek } from './useOnSeek';
|
|
4
|
+
export { useOnPlaybackProgressChange } from './useOnPlaybackProgressChange';
|
|
5
|
+
export { useAndroidAutoConnection } from './useAndroidAutoConnection';
|
|
6
|
+
export { useAudioDevices } from './useAudioDevices';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { useOnChangeTrack } from './useOnChangeTrack';
|
|
2
|
+
export { useOnPlaybackStateChange } from './useOnPlaybackStateChange';
|
|
3
|
+
export { useOnSeek } from './useOnSeek';
|
|
4
|
+
export { useOnPlaybackProgressChange } from './useOnPlaybackProgressChange';
|
|
5
|
+
export { useAndroidAutoConnection } from './useAndroidAutoConnection';
|
|
6
|
+
export { useAudioDevices } from './useAudioDevices';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook to detect Android Auto connection status using the official Android for Cars API
|
|
3
|
+
* Based on: https://developer.android.com/training/cars/apps#car-connection
|
|
4
|
+
*
|
|
5
|
+
* @returns Object with isConnected boolean
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const { isConnected } = useAndroidAutoConnection();
|
|
9
|
+
* console.log('Android Auto connected:', isConnected);
|
|
10
|
+
*/
|
|
11
|
+
export declare function useAndroidAutoConnection(): {
|
|
12
|
+
isConnected: boolean;
|
|
13
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { TrackPlayer } from '../index';
|
|
3
|
+
/**
|
|
4
|
+
* Hook to detect Android Auto connection status using the official Android for Cars API
|
|
5
|
+
* Based on: https://developer.android.com/training/cars/apps#car-connection
|
|
6
|
+
*
|
|
7
|
+
* @returns Object with isConnected boolean
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const { isConnected } = useAndroidAutoConnection();
|
|
11
|
+
* console.log('Android Auto connected:', isConnected);
|
|
12
|
+
*/
|
|
13
|
+
export function useAndroidAutoConnection() {
|
|
14
|
+
const [isConnected, setIsConnected] = useState(false);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
// Set initial state
|
|
17
|
+
const initialState = TrackPlayer.isAndroidAutoConnected();
|
|
18
|
+
setIsConnected(initialState);
|
|
19
|
+
// Listen for connection changes
|
|
20
|
+
TrackPlayer.onAndroidAutoConnectionChange((connected) => {
|
|
21
|
+
setIsConnected(connected);
|
|
22
|
+
console.log('🚗 Android Auto connection changed:', connected);
|
|
23
|
+
});
|
|
24
|
+
}, []);
|
|
25
|
+
return { isConnected };
|
|
26
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { TAudioDevice } from '../specs/AudioDevices.nitro';
|
|
2
|
+
/**
|
|
3
|
+
* Hook to get audio devices (Android only)
|
|
4
|
+
*
|
|
5
|
+
* Polls for device changes every 2 seconds
|
|
6
|
+
*
|
|
7
|
+
* @returns Object containing the current list of audio devices
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* function MyComponent() {
|
|
12
|
+
* const { devices } = useAudioDevices()
|
|
13
|
+
*
|
|
14
|
+
* return (
|
|
15
|
+
* <View>
|
|
16
|
+
* {devices.map(device => (
|
|
17
|
+
* <Text key={device.id}>{device.name}</Text>
|
|
18
|
+
* ))}
|
|
19
|
+
* </View>
|
|
20
|
+
* )
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function useAudioDevices(): {
|
|
25
|
+
devices: TAudioDevice[];
|
|
26
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { Platform } from 'react-native';
|
|
3
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
4
|
+
/**
|
|
5
|
+
* Hook to get audio devices (Android only)
|
|
6
|
+
*
|
|
7
|
+
* Polls for device changes every 2 seconds
|
|
8
|
+
*
|
|
9
|
+
* @returns Object containing the current list of audio devices
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* function MyComponent() {
|
|
14
|
+
* const { devices } = useAudioDevices()
|
|
15
|
+
*
|
|
16
|
+
* return (
|
|
17
|
+
* <View>
|
|
18
|
+
* {devices.map(device => (
|
|
19
|
+
* <Text key={device.id}>{device.name}</Text>
|
|
20
|
+
* ))}
|
|
21
|
+
* </View>
|
|
22
|
+
* )
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export function useAudioDevices() {
|
|
27
|
+
const [devices, setDevices] = useState([]);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (Platform.OS !== 'android') {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
const AudioDevices = NitroModules.createHybridObject('AudioDevices');
|
|
34
|
+
// Get initial devices
|
|
35
|
+
const updateDevices = () => {
|
|
36
|
+
try {
|
|
37
|
+
const currentDevices = AudioDevices.getAudioDevices();
|
|
38
|
+
setDevices(currentDevices);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
console.error('Error getting audio devices:', error);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
updateDevices();
|
|
45
|
+
// Poll for changes every 2 seconds
|
|
46
|
+
const interval = setInterval(updateDevices, 2000);
|
|
47
|
+
return () => clearInterval(interval);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
console.error('Error setting up audio devices polling:', error);
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
}, []);
|
|
54
|
+
return { devices };
|
|
55
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TrackItem, Reason } from '../types/PlayerQueue';
|
|
2
|
+
/**
|
|
3
|
+
* Hook to get the current track and track change reason
|
|
4
|
+
* @returns Object with current track and reason, or undefined if no track is playing
|
|
5
|
+
*/
|
|
6
|
+
export declare function useOnChangeTrack(): {
|
|
7
|
+
track: TrackItem | undefined;
|
|
8
|
+
reason: Reason | undefined;
|
|
9
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { TrackPlayer } from '../index';
|
|
3
|
+
/**
|
|
4
|
+
* Hook to get the current track and track change reason
|
|
5
|
+
* @returns Object with current track and reason, or undefined if no track is playing
|
|
6
|
+
*/
|
|
7
|
+
export function useOnChangeTrack() {
|
|
8
|
+
const [track, setTrack] = useState(undefined);
|
|
9
|
+
const [reason, setReason] = useState(undefined);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
TrackPlayer.onChangeTrack((newTrack, newReason) => {
|
|
12
|
+
setTrack(newTrack);
|
|
13
|
+
setReason(newReason);
|
|
14
|
+
});
|
|
15
|
+
}, []);
|
|
16
|
+
return { track, reason };
|
|
17
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook to get the current playback progress
|
|
3
|
+
* @returns Object with current position, total duration, and manual seek indicator
|
|
4
|
+
*/
|
|
5
|
+
export declare function useOnPlaybackProgressChange(): {
|
|
6
|
+
position: number;
|
|
7
|
+
totalDuration: number;
|
|
8
|
+
isManuallySeeked: boolean | undefined;
|
|
9
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { TrackPlayer } from '../index';
|
|
3
|
+
/**
|
|
4
|
+
* Hook to get the current playback progress
|
|
5
|
+
* @returns Object with current position, total duration, and manual seek indicator
|
|
6
|
+
*/
|
|
7
|
+
export function useOnPlaybackProgressChange() {
|
|
8
|
+
const [position, setPosition] = useState(0);
|
|
9
|
+
const [totalDuration, setTotalDuration] = useState(0);
|
|
10
|
+
const [isManuallySeeked, setIsManuallySeeked] = useState(undefined);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
TrackPlayer.onPlaybackProgressChange((newPosition, newTotalDuration, newIsManuallySeeked) => {
|
|
13
|
+
setPosition(newPosition);
|
|
14
|
+
setTotalDuration(newTotalDuration);
|
|
15
|
+
setIsManuallySeeked(newIsManuallySeeked);
|
|
16
|
+
});
|
|
17
|
+
}, []);
|
|
18
|
+
return { position, totalDuration, isManuallySeeked };
|
|
19
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TrackPlayerState, Reason } from '../types/PlayerQueue';
|
|
2
|
+
/**
|
|
3
|
+
* Hook to get the current playback state and reason
|
|
4
|
+
* @returns Object with current playback state and reason
|
|
5
|
+
*/
|
|
6
|
+
export declare function useOnPlaybackStateChange(): {
|
|
7
|
+
state: TrackPlayerState | undefined;
|
|
8
|
+
reason: Reason | undefined;
|
|
9
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { TrackPlayer } from '../index';
|
|
3
|
+
/**
|
|
4
|
+
* Hook to get the current playback state and reason
|
|
5
|
+
* @returns Object with current playback state and reason
|
|
6
|
+
*/
|
|
7
|
+
export function useOnPlaybackStateChange() {
|
|
8
|
+
const [state, setState] = useState(undefined);
|
|
9
|
+
const [reason, setReason] = useState(undefined);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
TrackPlayer.onPlaybackStateChange((newState, newReason) => {
|
|
12
|
+
setState(newState);
|
|
13
|
+
setReason(newReason);
|
|
14
|
+
});
|
|
15
|
+
}, []);
|
|
16
|
+
return { state, reason };
|
|
17
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook to get the last seek event information
|
|
3
|
+
* @returns Object with last seek position and total duration, or undefined if no seek has occurred
|
|
4
|
+
*/
|
|
5
|
+
export declare function useOnSeek(): {
|
|
6
|
+
position: number | undefined;
|
|
7
|
+
totalDuration: number | undefined;
|
|
8
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { TrackPlayer } from '../index';
|
|
3
|
+
/**
|
|
4
|
+
* Hook to get the last seek event information
|
|
5
|
+
* @returns Object with last seek position and total duration, or undefined if no seek has occurred
|
|
6
|
+
*/
|
|
7
|
+
export function useOnSeek() {
|
|
8
|
+
const [position, setPosition] = useState(undefined);
|
|
9
|
+
const [totalDuration, setTotalDuration] = useState(undefined);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
TrackPlayer.onSeek((newPosition, newTotalDuration) => {
|
|
12
|
+
setPosition(newPosition);
|
|
13
|
+
setTotalDuration(newTotalDuration);
|
|
14
|
+
});
|
|
15
|
+
}, []);
|
|
16
|
+
return { position, totalDuration };
|
|
17
|
+
}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PlayerQueue as PlayerQueueType, TrackPlayer as TrackPlayerType } from './specs/TrackPlayer.nitro';
|
|
2
|
+
import type { AndroidAutoMediaLibrary as AndroidAutoMediaLibraryType } from './specs/AndroidAutoMediaLibrary.nitro';
|
|
3
|
+
import type { AudioDevices as AudioDevicesType } from './specs/AudioDevices.nitro';
|
|
4
|
+
import type { AudioRoutePicker as AudioRoutePickerType } from './specs/AudioRoutePicker.nitro';
|
|
5
|
+
export declare const PlayerQueue: PlayerQueueType;
|
|
6
|
+
export declare const TrackPlayer: TrackPlayerType;
|
|
7
|
+
export declare const AndroidAutoMediaLibrary: AndroidAutoMediaLibraryType | null;
|
|
8
|
+
export declare const AudioDevices: AudioDevicesType | null;
|
|
9
|
+
export declare const AudioRoutePicker: AudioRoutePickerType | null;
|
|
10
|
+
export * from './hooks';
|
|
11
|
+
export * from './types/PlayerQueue';
|
|
12
|
+
export * from './types/AndroidAutoMediaLibrary';
|
|
13
|
+
export type { TAudioDevice } from './specs/AudioDevices.nitro';
|
|
14
|
+
export type { RepeatMode } from './specs/TrackPlayer.nitro';
|
|
15
|
+
export { AndroidAutoMediaLibraryHelper } from './utils/androidAutoMediaLibrary';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// TODO: Export all HybridObjects here for the user
|
|
2
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
3
|
+
import { Platform } from 'react-native';
|
|
4
|
+
export const PlayerQueue = NitroModules.createHybridObject('PlayerQueue');
|
|
5
|
+
export const TrackPlayer = NitroModules.createHybridObject('TrackPlayer');
|
|
6
|
+
// Android-only: Android Auto Media Library
|
|
7
|
+
export const AndroidAutoMediaLibrary = Platform.OS === 'android'
|
|
8
|
+
? NitroModules.createHybridObject('AndroidAutoMediaLibrary')
|
|
9
|
+
: null;
|
|
10
|
+
// Android-only: Audio Devices
|
|
11
|
+
export const AudioDevices = Platform.OS === 'android'
|
|
12
|
+
? NitroModules.createHybridObject('AudioDevices')
|
|
13
|
+
: null;
|
|
14
|
+
// iOS-only: Audio Route Picker
|
|
15
|
+
export const AudioRoutePicker = Platform.OS === 'ios'
|
|
16
|
+
? NitroModules.createHybridObject('AudioRoutePicker')
|
|
17
|
+
: null;
|
|
18
|
+
// Export hooks
|
|
19
|
+
export * from './hooks';
|
|
20
|
+
// Export types
|
|
21
|
+
export * from './types/PlayerQueue';
|
|
22
|
+
export * from './types/AndroidAutoMediaLibrary';
|
|
23
|
+
// Export utilities
|
|
24
|
+
export { AndroidAutoMediaLibraryHelper } from './utils/androidAutoMediaLibrary';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
+
/**
|
|
3
|
+
* Android Auto Media Library Manager
|
|
4
|
+
* Android-only HybridObject for managing Android Auto media browser structure
|
|
5
|
+
*/
|
|
6
|
+
export interface AndroidAutoMediaLibrary extends HybridObject<{
|
|
7
|
+
android: 'kotlin';
|
|
8
|
+
}> {
|
|
9
|
+
/**
|
|
10
|
+
* Set the Android Auto media library structure
|
|
11
|
+
* This defines what folders and playlists appear in Android Auto
|
|
12
|
+
*
|
|
13
|
+
* @param libraryJson - JSON string of the MediaLibrary structure
|
|
14
|
+
*/
|
|
15
|
+
setMediaLibrary(libraryJson: string): void;
|
|
16
|
+
/**
|
|
17
|
+
* Clear the Android Auto media library
|
|
18
|
+
* Falls back to showing all playlists
|
|
19
|
+
*/
|
|
20
|
+
clearMediaLibrary(): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
+
export type TAudioDevice = {
|
|
3
|
+
id: number;
|
|
4
|
+
name: string;
|
|
5
|
+
type: number;
|
|
6
|
+
isActive: boolean;
|
|
7
|
+
};
|
|
8
|
+
export interface AudioDevices extends HybridObject<{
|
|
9
|
+
android: 'kotlin';
|
|
10
|
+
}> {
|
|
11
|
+
/**
|
|
12
|
+
* Get the list of audio devices
|
|
13
|
+
*
|
|
14
|
+
* @returns The list of audio devices
|
|
15
|
+
*/
|
|
16
|
+
getAudioDevices(): TAudioDevice[];
|
|
17
|
+
/**
|
|
18
|
+
* Set the audio device
|
|
19
|
+
*
|
|
20
|
+
* @param deviceId - The ID of the audio device
|
|
21
|
+
* @returns True if the audio device was set successfully, false otherwise
|
|
22
|
+
*/
|
|
23
|
+
setAudioDevice(deviceId: number): boolean;
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
+
export interface AudioRoutePicker extends HybridObject<{
|
|
3
|
+
ios: 'swift';
|
|
4
|
+
}> {
|
|
5
|
+
/**
|
|
6
|
+
* Show the audio route picker view (iOS only)
|
|
7
|
+
* This presents a native AVRoutePickerView for selecting audio output devices like AirPlay
|
|
8
|
+
*/
|
|
9
|
+
showRoutePicker(): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
+
import type { QueueOperation, Reason, TrackItem, TrackPlayerState, PlayerState, PlayerConfig, Playlist } from '../types/PlayerQueue';
|
|
3
|
+
export interface PlayerQueue extends HybridObject<{
|
|
4
|
+
android: 'kotlin';
|
|
5
|
+
ios: 'swift';
|
|
6
|
+
}> {
|
|
7
|
+
createPlaylist(name: string, description?: string, artwork?: string): string;
|
|
8
|
+
deletePlaylist(playlistId: string): void;
|
|
9
|
+
updatePlaylist(playlistId: string, name?: string, description?: string, artwork?: string): void;
|
|
10
|
+
getPlaylist(playlistId: string): Playlist | null;
|
|
11
|
+
getAllPlaylists(): Playlist[];
|
|
12
|
+
addTrackToPlaylist(playlistId: string, track: TrackItem, index?: number): void;
|
|
13
|
+
addTracksToPlaylist(playlistId: string, tracks: TrackItem[], index?: number): void;
|
|
14
|
+
removeTrackFromPlaylist(playlistId: string, trackId: string): void;
|
|
15
|
+
reorderTrackInPlaylist(playlistId: string, trackId: string, newIndex: number): void;
|
|
16
|
+
loadPlaylist(playlistId: string): void;
|
|
17
|
+
getCurrentPlaylistId(): string | null;
|
|
18
|
+
onPlaylistsChanged(callback: (playlists: Playlist[], operation?: QueueOperation) => void): void;
|
|
19
|
+
onPlaylistChanged(callback: (playlistId: string, playlist: Playlist, operation?: QueueOperation) => void): void;
|
|
20
|
+
}
|
|
21
|
+
export type RepeatMode = 'off' | 'Playlist' | 'track';
|
|
22
|
+
export interface TrackPlayer extends HybridObject<{
|
|
23
|
+
android: 'kotlin';
|
|
24
|
+
ios: 'swift';
|
|
25
|
+
}> {
|
|
26
|
+
play(): void;
|
|
27
|
+
pause(): void;
|
|
28
|
+
playSong(songId: string, fromPlaylist?: string): void;
|
|
29
|
+
skipToNext(): void;
|
|
30
|
+
skipToPrevious(): void;
|
|
31
|
+
seek(position: number): void;
|
|
32
|
+
getState(): PlayerState;
|
|
33
|
+
setRepeatMode(mode: RepeatMode): boolean;
|
|
34
|
+
configure(config: PlayerConfig): void;
|
|
35
|
+
onChangeTrack(callback: (track: TrackItem, reason?: Reason) => void): void;
|
|
36
|
+
onPlaybackStateChange(callback: (state: TrackPlayerState, reason?: Reason) => void): void;
|
|
37
|
+
onSeek(callback: (position: number, totalDuration: number) => void): void;
|
|
38
|
+
onPlaybackProgressChange(callback: (position: number, totalDuration: number, isManuallySeeked?: boolean) => void): void;
|
|
39
|
+
onAndroidAutoConnectionChange(callback: (connected: boolean) => void): void;
|
|
40
|
+
isAndroidAutoConnected(): boolean;
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Layout type for the Android Auto media browser
|
|
3
|
+
*/
|
|
4
|
+
export type LayoutType = 'grid' | 'list';
|
|
5
|
+
/**
|
|
6
|
+
* Media type for different kinds of content
|
|
7
|
+
*/
|
|
8
|
+
export type MediaType = 'folder' | 'audio' | 'playlist';
|
|
9
|
+
/**
|
|
10
|
+
* Media item that can be displayed in Android Auto
|
|
11
|
+
*/
|
|
12
|
+
export interface MediaItem {
|
|
13
|
+
/** Unique identifier for the media item */
|
|
14
|
+
id: string;
|
|
15
|
+
/** Display title */
|
|
16
|
+
title: string;
|
|
17
|
+
/** Optional subtitle/description */
|
|
18
|
+
subtitle?: string;
|
|
19
|
+
/** Optional icon/artwork URL */
|
|
20
|
+
iconUrl?: string;
|
|
21
|
+
/** Whether this item can be played directly */
|
|
22
|
+
isPlayable: boolean;
|
|
23
|
+
/** Media type */
|
|
24
|
+
mediaType: MediaType;
|
|
25
|
+
/** Reference to playlist ID (for playlist items) - will load tracks from this playlist */
|
|
26
|
+
playlistId?: string;
|
|
27
|
+
/** Child items for browsable folders */
|
|
28
|
+
children?: MediaItem[];
|
|
29
|
+
/** Layout type for folder items (overrides library default) */
|
|
30
|
+
layoutType?: LayoutType;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Media library structure for Android Auto
|
|
34
|
+
*/
|
|
35
|
+
export interface MediaLibrary {
|
|
36
|
+
/** Layout type for the media browser (applies to all folders by default) */
|
|
37
|
+
layoutType: LayoutType;
|
|
38
|
+
/** Root level media items */
|
|
39
|
+
rootItems: MediaItem[];
|
|
40
|
+
/** Optional app name to display */
|
|
41
|
+
appName?: string;
|
|
42
|
+
/** Optional app icon URL */
|
|
43
|
+
appIconUrl?: string;
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface TrackItem {
|
|
2
|
+
id: string;
|
|
3
|
+
title: string;
|
|
4
|
+
artist: string;
|
|
5
|
+
album: string;
|
|
6
|
+
duration: number;
|
|
7
|
+
url: string;
|
|
8
|
+
artwork?: string | null;
|
|
9
|
+
}
|
|
10
|
+
export interface Playlist {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
description?: string | null;
|
|
14
|
+
artwork?: string | null;
|
|
15
|
+
tracks: TrackItem[];
|
|
16
|
+
}
|
|
17
|
+
export type QueueOperation = 'add' | 'remove' | 'clear' | 'update';
|
|
18
|
+
export type TrackPlayerState = 'playing' | 'paused' | 'stopped';
|
|
19
|
+
export type Reason = 'user_action' | 'skip' | 'end' | 'error';
|
|
20
|
+
export interface PlayerState {
|
|
21
|
+
currentTrack: TrackItem | null;
|
|
22
|
+
currentPosition: number;
|
|
23
|
+
totalDuration: number;
|
|
24
|
+
currentState: TrackPlayerState;
|
|
25
|
+
currentPlaylistId: string | null;
|
|
26
|
+
currentIndex: number;
|
|
27
|
+
}
|
|
28
|
+
export interface PlayerConfig {
|
|
29
|
+
androidAutoEnabled?: boolean;
|
|
30
|
+
carPlayEnabled?: boolean;
|
|
31
|
+
showInNotification?: boolean;
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { MediaLibrary } from '../types/AndroidAutoMediaLibrary';
|
|
2
|
+
/**
|
|
3
|
+
* Helper utilities for Android Auto Media Library
|
|
4
|
+
* Android-only functionality
|
|
5
|
+
*/
|
|
6
|
+
export declare const AndroidAutoMediaLibraryHelper: {
|
|
7
|
+
/**
|
|
8
|
+
* Set the Android Auto media library structure
|
|
9
|
+
* This defines what folders and playlists appear in Android Auto
|
|
10
|
+
*
|
|
11
|
+
* @param library - The media library structure
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* AndroidAutoMediaLibraryHelper.set({
|
|
16
|
+
* layoutType: 'grid',
|
|
17
|
+
* rootItems: [
|
|
18
|
+
* {
|
|
19
|
+
* id: 'my_music',
|
|
20
|
+
* title: 'My Music',
|
|
21
|
+
* mediaType: 'folder',
|
|
22
|
+
* isPlayable: false,
|
|
23
|
+
* children: [
|
|
24
|
+
* {
|
|
25
|
+
* id: 'favorites',
|
|
26
|
+
* title: 'Favorites',
|
|
27
|
+
* mediaType: 'playlist',
|
|
28
|
+
* playlistId: 'favorites-playlist-id', // References a playlist created with PlayerQueue
|
|
29
|
+
* isPlayable: false,
|
|
30
|
+
* },
|
|
31
|
+
* ],
|
|
32
|
+
* },
|
|
33
|
+
* ],
|
|
34
|
+
* })
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
set: (library: MediaLibrary) => void;
|
|
38
|
+
/**
|
|
39
|
+
* Clear the Android Auto media library
|
|
40
|
+
* Falls back to showing all playlists
|
|
41
|
+
*/
|
|
42
|
+
clear: () => void;
|
|
43
|
+
/**
|
|
44
|
+
* Check if Android Auto Media Library is available (Android only)
|
|
45
|
+
*/
|
|
46
|
+
isAvailable: () => boolean;
|
|
47
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { AndroidAutoMediaLibrary as AndroidAutoMediaLibraryModule } from '../index';
|
|
2
|
+
/**
|
|
3
|
+
* Helper utilities for Android Auto Media Library
|
|
4
|
+
* Android-only functionality
|
|
5
|
+
*/
|
|
6
|
+
export const AndroidAutoMediaLibraryHelper = {
|
|
7
|
+
/**
|
|
8
|
+
* Set the Android Auto media library structure
|
|
9
|
+
* This defines what folders and playlists appear in Android Auto
|
|
10
|
+
*
|
|
11
|
+
* @param library - The media library structure
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* AndroidAutoMediaLibraryHelper.set({
|
|
16
|
+
* layoutType: 'grid',
|
|
17
|
+
* rootItems: [
|
|
18
|
+
* {
|
|
19
|
+
* id: 'my_music',
|
|
20
|
+
* title: 'My Music',
|
|
21
|
+
* mediaType: 'folder',
|
|
22
|
+
* isPlayable: false,
|
|
23
|
+
* children: [
|
|
24
|
+
* {
|
|
25
|
+
* id: 'favorites',
|
|
26
|
+
* title: 'Favorites',
|
|
27
|
+
* mediaType: 'playlist',
|
|
28
|
+
* playlistId: 'favorites-playlist-id', // References a playlist created with PlayerQueue
|
|
29
|
+
* isPlayable: false,
|
|
30
|
+
* },
|
|
31
|
+
* ],
|
|
32
|
+
* },
|
|
33
|
+
* ],
|
|
34
|
+
* })
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
set: (library) => {
|
|
38
|
+
if (!AndroidAutoMediaLibraryModule) {
|
|
39
|
+
console.warn('AndroidAutoMediaLibrary is only available on Android');
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const json = JSON.stringify(library);
|
|
43
|
+
AndroidAutoMediaLibraryModule.setMediaLibrary(json);
|
|
44
|
+
},
|
|
45
|
+
/**
|
|
46
|
+
* Clear the Android Auto media library
|
|
47
|
+
* Falls back to showing all playlists
|
|
48
|
+
*/
|
|
49
|
+
clear: () => {
|
|
50
|
+
if (!AndroidAutoMediaLibraryModule) {
|
|
51
|
+
console.warn('AndroidAutoMediaLibrary is only available on Android');
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
AndroidAutoMediaLibraryModule.clearMediaLibrary();
|
|
55
|
+
},
|
|
56
|
+
/**
|
|
57
|
+
* Check if Android Auto Media Library is available (Android only)
|
|
58
|
+
*/
|
|
59
|
+
isAvailable: () => {
|
|
60
|
+
return AndroidAutoMediaLibraryModule !== null;
|
|
61
|
+
},
|
|
62
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nitro-player",
|
|
3
|
-
"version": "0.3.0-alpha.
|
|
3
|
+
"version": "0.3.0-alpha.6",
|
|
4
4
|
"description": "react-native-nitro-player",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"module": "lib/index",
|
|
@@ -44,14 +44,14 @@
|
|
|
44
44
|
],
|
|
45
45
|
"repository": {
|
|
46
46
|
"type": "git",
|
|
47
|
-
"url": "git+https://github.com/
|
|
47
|
+
"url": "git+https://github.com/riteshshukla04/react-native-nitro-player"
|
|
48
48
|
},
|
|
49
|
-
"author": "
|
|
49
|
+
"author": "Ritesh Shukla <riteshshukla2381@gmail.com> (https://github.com/riteshshukla04)",
|
|
50
50
|
"license": "MIT",
|
|
51
51
|
"bugs": {
|
|
52
|
-
"url": "https://github.com/
|
|
52
|
+
"url": "https://github.com/riteshshukla04/react-native-nitro-player/issues"
|
|
53
53
|
},
|
|
54
|
-
"homepage": "https://github.com/
|
|
54
|
+
"homepage": "https://github.com/riteshshukla04/react-native-nitro-player#readme",
|
|
55
55
|
"publishConfig": {
|
|
56
56
|
"registry": "https://registry.npmjs.org/"
|
|
57
57
|
},
|
|
@@ -123,9 +123,6 @@
|
|
|
123
123
|
"github": {
|
|
124
124
|
"release": true
|
|
125
125
|
},
|
|
126
|
-
"hooks": {
|
|
127
|
-
"after:bump": "bun run build"
|
|
128
|
-
},
|
|
129
126
|
"plugins": {
|
|
130
127
|
"@release-it/bumper": {
|
|
131
128
|
"in": "package.json",
|