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
1
class MainActivity : AppCompatActivity() {
2
3
fun playTrack() {
4
val track = STTrack()
5
STPlayer.getInstance()?.play(track)
6
}
7
8
fun playPlaylist() {
9
val playlist = STPlaylist()
10
STPlayer.getInstance()?.play(playlist)
11
}
12
}
13
Copied!
SampleViewController.swift
1
import UIKit
2
import StayTunedSDK
3
4
class SampleViewController: UIViewController {
5
6
private func playTrack() {
7
let track = STTrack(/*..*/)
8
STPlayer.shared?.play(track)
9
}
10
11
private func playPlaylist() {
12
let playlist = STPlaylist(/*..*/)
13
STPlayer.shared?.play(playlist)
14
}
15
16
}
Copied!
JS / TS
1
// Play track (will create a playlist of 1 track)
2
const track = { /* one track */ };
3
staytunedSDK.STPlayer.play(track);
4
5
// Play playlist
6
const playlist = {
7
name: globalContent.title,
8
trackList: [
9
{ /* one track */ },
10
{ /* another track */ }
11
]
12
}
13
staytunedSDK.STPlayer.play(playlist);
14
15
// Player controls
16
staytunedSDK.STPlayer.play(); // Play current track
17
staytunedSDK.STPlayer.stop(); // Stop / pause
18
staytunedSDK.STPlayer.next(); // Next track in the playlist
19
staytunedSDK.STPlayer.prev(); // Previous track
20
staytunedSDK.STPlayer.seekTo(time); // Jump to time
21
staytunedSDK.STPlayer.rewind(time = 30); // Rewind 30 sec
22
staytunedSDK.STPlayer.fastForward(time = 30); // Fast forward 30 sec
Copied!
1
import { STPlayer, STContent, STTrack, STPlaylist } from "@staytuned-io/cordova-typescript";
2
3
// Play a single track
4
const track = new STTrack();
5
STPlayer.getInstance().playTrack(track);
6
7
// Play a set of track
8
const playlist = new STPlayList();
9
STPlayer.getInstance().play(playlist);
10
11
STPlayer.getInstance().stop();
12
STPlayer.getInstance().resume();
Copied!

Display Embedded Player

You can display the player in different format (chip, mini-player, full-scren).
Android
iOS
Web
Cordova
1
class MainActivity : AppCompatActivity() {
2
3
private fun showPlayer() {
4
STPlayer.getInstance()?.launchUI(applicationContext)
5
}
6
}
Copied!
SampleViewController.swift
1
import UIKit
2
import StayTunedSDK
3
4
class SampleViewController: UIViewController {
5
6
private func showPlayer() {
7
STPlayer.shared?.openExpand(presenter: self)
8
}
9
10
private func displayChip() {
11
STFloatingChip.shared?.displayChip(in: self)
12
}
13
14
private func displayMiniPlayer() {
15
STMiniPlayer.shared?.display(in: self, with: STFloatingChipConfiguration())
16
}
17
}
Copied!
Coming soon
1
import { STPlayer } from "@staytuned-io/cordova-typescript";
2
3
// open the player screen
4
STPlayer.getInstance().launchUI();
Copied!

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
1
class MainActivity : AppCompatActivity() {
2
3
fun showPlayer() {
4
STPlayer.getInstance()?.configuration?.isContentCellVisible = true
5
STPlayer.getInstance()?.configuration?.onContentCellClick =
6
{ playerActivity, content ->
7
// your code here
8
}
9
}
10
}
Copied!
1
import UIKit
2
import StayTunedSDK
3
4
class SampleViewController: UIViewController {
5
6
private func showPlayer() {
7
let configuration: STPlayerConfiguration = .init(
8
isContentCellVisible: true,
9
onContentCellClick: { navigationController in
10
// Your code here
11
}
12
)
13
STPlayer.shared?.setConfiguration(configuration)
14
}
15
16
}
Copied!

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
1
class MainActivity : AppCompatActivity() {
2
3
fun showPlayer() {
4
STPlayer.getInstance()?.configuration?.preferredAudioQuality = STAudioQualityEnum.HD
5
STPlayer.getInstance()?.currentTrackAudioQuality?.observe(this, Observer { quality ->
6
Log.d(LOG_TAG, "current track quality : $quality")
7
})
8
}
9
}
Copied!
SampleViewController.swift
1
import UIKit
2
import StayTunedSDK
3
4
class SampleViewController: UIViewController {
5
6
private func setAudioHD() {
7
STPlayer.shared?.setPreferredAudioQuality(.hd)
8
}
9
10
private func observeAudioQuality() {
11
STPlayer.shared?.add(observer: self)
12
}
13
}
14
15
extension SampleViewController: STPlayerObserver {
16
17
func playerCurrentTrackAudioQualityDidChange(to value: STAudioQuality) {
18
print("quality did change to \(value.rawValue)")
19
}
20
21
}
Copied!
1
// 'normal' or 'hd'
2
staytunedSDK.STPlayer.setPreferredAudioQuality('hd');
3
4
// Get current track audio quality
5
staytunedSDK.STPlayer.currentTrackAudioQuality$.subscribe((audioQuality) => {...});
Copied!
1
// Coming soon
Copied!