Skip to content

Commit

Permalink
feat: add track durations
Browse files Browse the repository at this point in the history
  • Loading branch information
Pashkagreen committed Jan 20, 2024
1 parent 8bd84c0 commit a724da5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ios/MusicModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@ class MusicModule: RCTEventEmitter {

private func sendPlaybackStateUpdate() {
let state = SystemMusicPlayer.shared.state
let playbackInterval = SystemMusicPlayer.shared.playbackTime
let playbackStatusDescription = describePlaybackStatus(state.playbackStatus)
let playbackRate = state.playbackRate

if lastReportedPlaybackStatus != state.playbackStatus {
self.getCurrentSongInfo { songInfo in
var playbackInfo: [String: Any] = [
"playbackRate": playbackRate,
"playbackStatus": playbackStatusDescription
"playbackStatus": playbackStatusDescription,
"playbackTime": playbackInterval
]

if let songInfo = songInfo {
Expand Down Expand Up @@ -102,6 +104,7 @@ class MusicModule: RCTEventEmitter {
case .song(let song):
print("Current song: \(song.title) - \(song.artistName)")
print("Current song ID: \(String(describing: song.id))")
print("Current song duration: \(song.duration ?? 0)")

Task {
let songID = song.id
Expand Down Expand Up @@ -270,7 +273,8 @@ class MusicModule: RCTEventEmitter {
"id": String(describing: song.id),
"title": song.title,
"artistName": song.artistName,
"artworkUrl": artworkUrlString
"artworkUrl": artworkUrlString,
"duration": String(song.duration ?? 0)
]
}

Expand Down
1 change: 1 addition & 0 deletions src/types/playback-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export interface IPlaybackState {
currentSong: ISong;
playbackRate: number;
playbackStatus: PlaybackStatus;
playbackTime: number;
}
1 change: 1 addition & 0 deletions src/types/song.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export interface ISong {
title: string;
artworkUrl: string;
id: string;
duration: number;
}

0 comments on commit a724da5

Please sign in to comment.