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.

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
Android
class MainActivity : AppCompatActivity() {
fun playTrack() {
val track = STTrack()
STPlayer.getInstance()?.play(track)
}
fun playPlaylist() {
val playlist = STPlaylist()
STPlayer.getInstance()?.play(playlist)
}
}
iOS
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)
}
}
Web
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
Cordova
import { STPlayer, STContent, STTrack, STPlaylist } from "@staytuned-io/cordova-typescript";
// Play a single track
const track = new STTrack();
STPlayer.getInstance().play(track);
// Play a set of track
const playlist = new STPlayList();
STPlayer.getInstance().play(playlist);
STPlayer.getInstance().stop();
STPlayer.getInstance().resume();

The SDK can manages itself the UI part.

Android
iOS
Web
Cordova
Android
class MainActivity : AppCompatActivity() {
fun showPlayer() {
STPlayer.getInstance()?.launchUI(applicationContext)
}
}
iOS
SampleViewController.swift
import UIKit
import StayTuned
class SampleViewController: UIViewController {
private func showPlayer() {
STPlayer.shared?.openExpand(presenter: self)
}
private func displayChip() {
STPlayer.shared?.displayChip(in: self)
}
private func displayMiniPlayer() {
STPlayer.shared?.setMiniPlayer(in: self)
STPlayer.shared?.displayMiniPlayer(true)
}
}
Web

Coming soon

Cordova
import { STPlayer } from "@staytuned-io/cordova-typescript";
// open the player screen
STPlayer.getInstance().launchUI();