Skip to content

Commit

Permalink
fix(ts): add null to getCurrentTrack return type (#1681)
Browse files Browse the repository at this point in the history
  • Loading branch information
qmx authored Sep 3, 2022
1 parent 6b25dfe commit 096ec68
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,12 @@ class MusicModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaM
@ReactMethod
fun getCurrentTrack(callback: Promise) = scope.launch {
if (verifyServiceBoundOrReject(callback)) return@launch

callback.resolve(musicService.getCurrentTrackIndex())
val currentTrackIndex = musicService.getCurrentTrackIndex()
if (currentTrackIndex >= 0 || currentTrackIndex < musicService.tracks.size) {
callback.resolve(currentTrackIndex)
} else {
callback.resolve(null)
}
}

@ReactMethod
Expand Down
2 changes: 1 addition & 1 deletion src/trackPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ async function getQueue(): Promise<Track[]> {
/**
* Gets the index of the current track.
*/
async function getCurrentTrack(): Promise<number> {
async function getCurrentTrack(): Promise<number | null> {
return TrackPlayer.getCurrentTrack();
}

Expand Down

0 comments on commit 096ec68

Please sign in to comment.