react-native-nitro-player 0.3.0-alpha.6 → 0.3.0-alpha.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nitro-player",
3
- "version": "0.3.0-alpha.6",
3
+ "version": "0.3.0-alpha.8",
4
4
  "description": "react-native-nitro-player",
5
5
  "main": "lib/index",
6
6
  "module": "lib/index",
@@ -30,13 +30,14 @@
30
30
  "scripts": {
31
31
  "postinstall": "tsc || exit 0;",
32
32
  "typecheck": "tsc --noEmit",
33
- "clean": "rm -rf android/build node_modules/**/android/build lib nitrogen",
33
+ "clean": "rm -rf android/build node_modules/**/android/build lib nitrogen tsconfig.tsbuildinfo",
34
34
  "lint": "eslint \"**/*.{js,ts,tsx}\" --fix",
35
35
  "lint-ci": "eslint \"**/*.{js,ts,tsx}\" -f @jamesacarr/github-actions",
36
36
  "typescript": "tsc",
37
- "specs": "tsc --noEmit false && nitrogen --logLevel=\"debug\"",
37
+ "specs": "tsc && nitrogen --logLevel=\"debug\"",
38
+ "copy-readme": "cp ../README.md README.md",
38
39
  "release": "release-it",
39
- "build": "bun run clean && bun run specs && bun run typescript"
40
+ "build": "bun run clean && bun run specs && bun run typescript && bun run copy-readme"
40
41
  },
41
42
  "keywords": [
42
43
  "react-native",
@@ -123,6 +124,9 @@
123
124
  "github": {
124
125
  "release": true
125
126
  },
127
+ "hooks": {
128
+ "before:release": "bun run clean && bun run specs && bun run typescript && bun run copy-readme"
129
+ },
126
130
  "plugins": {
127
131
  "@release-it/bumper": {
128
132
  "in": "package.json",
@@ -4,3 +4,4 @@ export { useOnSeek } from './useOnSeek'
4
4
  export { useOnPlaybackProgressChange } from './useOnPlaybackProgressChange'
5
5
  export { useAndroidAutoConnection } from './useAndroidAutoConnection'
6
6
  export { useAudioDevices } from './useAudioDevices'
7
+ export { useNowPlaying } from './useNowPlaying'
@@ -0,0 +1,84 @@
1
+ import { useEffect, useState } from 'react'
2
+ import { TrackPlayer } from '../index'
3
+ import type { PlayerState } from '../types/PlayerQueue'
4
+
5
+ /**
6
+ * Hook to get the current player state (same as TrackPlayer.getState())
7
+ *
8
+ * This hook provides all player state information including:
9
+ * - Current track
10
+ * - Current position and duration
11
+ * - Playback state (playing, paused, stopped)
12
+ * - Current playlist ID
13
+ * - Current track index
14
+ *
15
+ * The hook polls getState() periodically and also listens to events
16
+ * for immediate updates when state changes.
17
+ *
18
+ * @returns PlayerState object with all current player information
19
+ *
20
+ * @example
21
+ * ```tsx
22
+ * function PlayerComponent() {
23
+ * const state = useNowPlaying()
24
+ *
25
+ * return (
26
+ * <View>
27
+ * {state.currentTrack && (
28
+ * <Text>Now Playing: {state.currentTrack.title}</Text>
29
+ * )}
30
+ * <Text>Position: {state.currentPosition} / {state.totalDuration}</Text>
31
+ * <Text>State: {state.currentState}</Text>
32
+ * <Text>Playlist: {state.currentPlaylistId || 'None'}</Text>
33
+ * <Text>Index: {state.currentIndex}</Text>
34
+ * </View>
35
+ * )
36
+ * }
37
+ * ```
38
+ */
39
+ export function useNowPlaying(): PlayerState {
40
+ const [state, setState] = useState<PlayerState>(() => {
41
+ // Get initial state
42
+ try {
43
+ return TrackPlayer.getState()
44
+ } catch (error) {
45
+ console.error('Error getting initial player state:', error)
46
+ // Return default state
47
+ return {
48
+ currentTrack: null,
49
+ currentPosition: 0,
50
+ totalDuration: 0,
51
+ currentState: 'stopped',
52
+ currentPlaylistId: null,
53
+ currentIndex: -1,
54
+ }
55
+ }
56
+ })
57
+
58
+ useEffect(() => {
59
+ // Update state function
60
+ const updateState = () => {
61
+ try {
62
+ const newState = TrackPlayer.getState()
63
+ setState(newState)
64
+ } catch (error) {
65
+ console.error('Error updating player state:', error)
66
+ }
67
+ }
68
+
69
+ // Get initial state
70
+ updateState()
71
+
72
+ // Listen to track changes
73
+ TrackPlayer.onChangeTrack(() => {
74
+ updateState()
75
+ })
76
+
77
+ // Listen to playback state changes
78
+ TrackPlayer.onPlaybackStateChange(() => {
79
+ updateState()
80
+ })
81
+ }, [])
82
+
83
+ return state
84
+ }
@@ -81,4 +81,5 @@ export interface TrackPlayer
81
81
  ): void
82
82
  onAndroidAutoConnectionChange(callback: (connected: boolean) => void): void
83
83
  isAndroidAutoConnected(): boolean
84
+ setVolume(volume: number): boolean
84
85
  }