Skip to content

Latest commit

 

History

History
91 lines (68 loc) · 3.9 KB

README.md

File metadata and controls

91 lines (68 loc) · 3.9 KB

Player

The TIDAL Player client for iOS.

The Player module encapsulates the playback functionality of TIDAL media products. The implementation uses Apple's AVPlayer as the media player. Check AVPlayer.

Features

  • Streaming and playing TIDAL catalog content.
  • Core playback functionality.
  • Media streaming, caching and error handling.
  • Automatic management of playback session event reporting.

Documentation

Usage

Install via Swift Package file

Add the dependency to your existing Package.swift file.

dependencies: [
    .package(url: "https://tidal-music.github.io/tidal-sdk-ios", from: "<VERSION>"))
]

Install via Swift Package Manager with Xcode

  1. Select "File » Add Packages Dependencies..." and enter the repository URL https://github.com/tidal-music/tidal-sdk-ios into the search bar (top right).
  2. Set the Dependency Rule to "Up to next major", and the version number to that you want.
  3. When "Choose Package Products for tidal-sdk-ios" appears, make sure to add Player, Auth and EventProducer at least to your target.

Playing a TIDAL Track

The Player depends on the Auth and EventProducer modules for authentication and event reporting handling. For detailed instructions on how to set them up, please refer to their guide.

Here's how to setup the Player and play a TIDAL track:

  1. Initialise the Player which depends on a CredentialsProvider from the Auth module and an EventSender from the EventProducer module.
let player = Player.bootstrap(
    listener: self,
    credentialsProvider: TidalAuth.shared,
    eventSender: TidalEventSender.shared
)
  1. Load and play a MediaProduct track.
player.load(
    MediaProduct(
        productType: ProductType.TRACK,
        productId: "PRODUCT_ID"
    )
)
player.play()
  1. The listener passed in the bootstrap process will receive the player events callbacks for the PlayerListener delegate.
let player = Player.bootstrap(
    ..
    listener: self,
    ..
)

extension ViewModel: PlayerListener {
    func stateChanged(to state: State) {
        print("New player state: \(state)")
    }
}

Running the Test App

The player module includes a test app that demonstrates how to setup the player and showcases its different functionalities.

As a prerequisite for the player to work, the client is required to be authenticated. You can learn more about the authentication flows in the Auth module. Note that currently only the Client Credentials flow is publicly supported. This enables the test app to play 30-second tracks previews. Full length playback is only enabled when the client is authenticated through Device Login or Authorization Code Flow.

In order to run the test app, please declare your client credentials in the PlayerViewModel class:

private let CLIENT_ID = "YOUR_CLIENT_ID"
private let CLIENT_SECRET = "YOUR_CLIENT_SECRET"

Note

You can obtain the CLIENT_ID and CLIENT_SECRET after signing up and creating an application in the TIDAL Developer Platform.