Skip to content

Commit

Permalink
Merge pull request #129 from tidal-music/alberto/fix-canPlay-isOfflin…
Browse files Browse the repository at this point in the history
…ed-offlineengine

[Player] Fix AVQueuePlayerWrapper.canPlay() for PlayableOfflinedMediaProduct
  • Loading branch information
asendra authored Oct 23, 2024
2 parents 4a87b1b + 5449b2e commit f26d0ab
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
7 changes: 6 additions & 1 deletion Sources/Player/Mocks/PlaybackEngine/PlayerMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ public final class PlayerMock: GenericMediaPlayer {

public init(cachePath: URL, featureFlagProvider: FeatureFlagProvider) {}

public func canPlay(productType: PlayerProductType, codec: PlayerAudioCodec?, mediaType: String?, isOfflined: Bool) -> Bool {
public func canPlay(
productType: PlayerProductType,
codec: PlayerAudioCodec?,
mediaType: String?,
isOfflined: Bool
) -> Bool {
true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct PlayableOfflinedMediaProduct: Equatable {
let audioSampleRate: Int?
let audioBitDepth: Int?
let videoQuality: VideoQuality?
let mediaType: String?
let mediaURL: URL
let licenseURL: URL?
let albumReplayGain: Float?
Expand All @@ -36,6 +37,7 @@ struct PlayableOfflinedMediaProduct: Equatable {
audioSampleRate = offlineEntry.audioSampleRate
audioBitDepth = offlineEntry.audioBitDepth
videoQuality = offlineEntry.videoQuality
mediaType = offlineEntry.mediaType
mediaURL = URL
licenseURL = offlineEntry.licenseURL
albumReplayGain = offlineEntry.albumReplayGain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ final class AVQueuePlayerWrapper: GenericMediaPlayer {
guard let codec else {
return false
}
return supportedCodecs.contains(codec) || (codec == .FLAC && !isOfflined)
// Because we need to support items downloaded with both the legacy and the new OfflineEngine
// We can't just add .FLAC to the 'supportedCodecs' array, and we need to depend on the mediaType
return supportedCodecs.contains(codec) || (codec == .FLAC && mediaType != MediaTypes.BTS)
}

func load(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ final class AVQueuePlayerWrapperLegacy: GenericMediaPlayer {
guard let codec else {
return false
}
return supportedCodecs.contains(codec) || (codec == .FLAC && !isOfflined)
// Because we need to support items downloaded with both the legacy and the new OfflineEngine
// We can't just add .FLAC to the 'supportedCodecs' array, and we need to depend on the mediaType
return supportedCodecs.contains(codec) || (codec == .FLAC && mediaType != MediaTypes.BTS)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ final class InternalPlayerLoader: PlayerLoader {
let player = try getPlayer(
for: offlinedProduct.audioMode,
and: offlinedProduct.audioQuality,
with: offlinedProduct.mediaType,
audioCodec: offlinedProduct.audioCodec,
isOfflined: true,
type: offlinedProduct.productType
)

Expand Down Expand Up @@ -100,6 +102,7 @@ final class InternalPlayerLoader: PlayerLoader {
let player = try getPlayer(
for: storedMediaProduct.audioMode,
and: storedMediaProduct.audioQuality,
with: MediaTypes.BTS,
audioCodec: storedMediaProduct.audioCodec,
isOfflined: true,
type: storedMediaProduct.productType
Expand Down Expand Up @@ -134,6 +137,7 @@ final class InternalPlayerLoader: PlayerLoader {
and: playbackInfo.audioQuality,
with: playbackInfo.mediaType,
audioCodec: playbackInfo.audioCodec,
isOfflined: false,
type: playbackInfo.productType
)
return await loadTrack(using: playbackInfo, with: loudnessNormalizer, and: licenseLoader, player: player)
Expand Down

0 comments on commit f26d0ab

Please sign in to comment.