Links

Play contents

In this section, we explain how to play content with the SDK

How to play content

The SDK is implementing an object call player, it can read what we call a track or a playlist.
Details for trackand playerare available in the API Reference section.
Do not forget to allow HTTP requests on iOS if you are trying to play an audio which is not hosted by StayTuned (see documentation).
You can start reading an audio by implementing the following sample lines. After calling one of these methods, the player will automatically launch the content.
Android
iOS
Web
Cordova
class MainActivity : AppCompatActivity() {
fun playTrack() {
val track = STTrack()
STPlayer.getInstance()?.play(track)
}
fun playPlaylist() {
val playlist = STPlaylist()
STPlayer.getInstance()?.play(playlist)
}
}
SampleViewController.swift
import UIKit
import StayTunedSDK
class SampleViewController: UIViewController {
private func playTrack() {
let track = STTrack(/*..*/)
STPlayer.shared?.play(track)
}
private func playPlaylist() {
let playlist = STPlaylist(/*..*/)
STPlayer.shared?.play(playlist)
}
}
JS / TS
// Play track (will create a playlist of 1 track)
const track = { /* one track */ };
staytunedSDK.STPlayer.play(track);
// Play playlist
const playlist = {
name: globalContent.title,
trackList: [
{ /* one track */ },
{ /* another track */ }
]
}
staytunedSDK.STPlayer.play(playlist);
// Player controls
staytunedSDK.STPlayer.play(); // Play current track
staytunedSDK.STPlayer.stop(); // Stop / pause
staytunedSDK.STPlayer.next(); // Next track in the playlist
staytunedSDK.STPlayer.prev(); // Previous track
staytunedSDK.STPlayer.seekTo(time); // Jump to time
staytunedSDK.STPlayer.rewind(time = 30); // Rewind 30 sec
staytunedSDK.STPlayer.fastForward(time = 30); // Fast forward 30 sec
import { STPlayer, STContent, STTrack, STPlaylist } from "@staytuned-io/cordova-typescript";
// Play a single track
const track = new STTrack();
STPlayer.getInstance().playTrack(track);
// Play a set of track
const playlist = new STPlayList();
STPlayer.getInstance().play(playlist);
STPlayer.getInstance().stop();
STPlayer.getInstance().resume();

Display Embedded Player

You can display the player in different format (chip, mini-player, full-scren).
Android
iOS
Web
Cordova
class MainActivity : AppCompatActivity() {
private fun showPlayer() {
STPlayer.getInstance()?.launchUI(applicationContext)
}
}
SampleViewController.swift
import UIKit
import StayTunedSDK
class SampleViewController: UIViewController {
private func showPlayer() {
STPlayer.shared?.openExpand(presenter: self)
}
private func displayChip() {
STFloatingChip.shared?.displayChip(in: self)
}
private func displayMiniPlayer() {
STMiniPlayer.shared?.display(in: self, with: STFloatingChipConfiguration())
}
}
Coming soon
import { STPlayer } from "@staytuned-io/cordova-typescript";
// open the player screen
STPlayer.getInstance().launchUI();

Customize and handle player's events

You have the opportunity to configure the player to present the content cell at the bottom of the player UI and to handle a tap event to show your custom view.
By default, the SDK will show the content cell.
Android
iOS
class MainActivity : AppCompatActivity() {
fun showPlayer() {
STPlayer.getInstance()?.configuration?.isContentCellVisible = true
STPlayer.getInstance()?.configuration?.onContentCellClick =
{ playerActivity, content ->
// your code here
}
}
}
import UIKit
import StayTunedSDK
class SampleViewController: UIViewController {
private func showPlayer() {
let configuration: STPlayerConfiguration = .init(
isContentCellVisible: true,
onContentCellClick: { navigationController in
// Your code here
}
)
STPlayer.shared?.setConfiguration(configuration)
}
}

Set preferred audio quality

Staytuned provides 2 available audio quality:
  • Normal
  • High Definition
The "normal" quality is applied if nothing is set but you can set another one as shown below.
Android
iOS
Web
Cordova
class MainActivity : AppCompatActivity() {
fun showPlayer() {
STPlayer.getInstance()?.configuration?.preferredAudioQuality = STAudioQualityEnum.HD
STPlayer.getInstance()?.currentTrackAudioQuality?.observe(this, Observer { quality ->
Log.d(LOG_TAG, "current track quality : $quality")
})
}
}
SampleViewController.swift
import UIKit
import StayTunedSDK
class SampleViewController: UIViewController {
private func setAudioHD() {
STPlayer.shared?.setPreferredAudioQuality(.hd)
}
private func observeAudioQuality() {
STPlayer.shared?.add(observer: self)
}
}
extension SampleViewController: STPlayerObserver {
func playerCurrentTrackAudioQualityDidChange(to value: STAudioQuality) {
print("quality did change to \(value.rawValue)")
}
}
// 'normal' or 'hd'
staytunedSDK.STPlayer.setPreferredAudioQuality('hd');
// Get current track audio quality
staytunedSDK.STPlayer.currentTrackAudioQuality$.subscribe((audioQuality) => {...});
// Coming soon