The SDK is implementing an object call player
, it can read what we call a track
or a playlist
.
Details for track
and player
are 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.
class MainActivity : AppCompatActivity() {fun playTrack() {val track = STTrack()STPlayer.getInstance()?.play(track)}fun playPlaylist() {val playlist = STPlaylist()STPlayer.getInstance()?.play(playlist)}}
SampleViewController.swiftimport UIKitimport StayTunedSDKclass 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 playlistconst playlist = {name: globalContent.title,trackList: [{ /* one track */ },{ /* another track */ }]}staytunedSDK.STPlayer.play(playlist);// Player controlsstaytunedSDK.STPlayer.play(); // Play current trackstaytunedSDK.STPlayer.stop(); // Stop / pausestaytunedSDK.STPlayer.next(); // Next track in the playliststaytunedSDK.STPlayer.prev(); // Previous trackstaytunedSDK.STPlayer.seekTo(time); // Jump to timestaytunedSDK.STPlayer.rewind(time = 30); // Rewind 30 secstaytunedSDK.STPlayer.fastForward(time = 30); // Fast forward 30 sec
import { STPlayer, STContent, STTrack, STPlaylist } from "@staytuned-io/cordova-typescript";// Play a single trackconst track = new STTrack();STPlayer.getInstance().playTrack(track);// Play a set of trackconst playlist = new STPlayList();STPlayer.getInstance().play(playlist);STPlayer.getInstance().stop();STPlayer.getInstance().resume();
You can display the player in different format (chip, mini-player, full-scren).
class MainActivity : AppCompatActivity() {private fun showPlayer() {STPlayer.getInstance()?.launchUI(applicationContext)}}
SampleViewController.swiftimport UIKitimport StayTunedSDKclass 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)}}
Coming soon
import { STPlayer } from "@staytuned-io/cordova-typescript";// open the player screenSTPlayer.getInstance().launchUI();
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.
class MainActivity : AppCompatActivity() {fun showPlayer() {STPlayer.getInstance()?.configuration?.isContentCellVisible = trueSTPlayer.getInstance()?.configuration?.onContentCellClick ={ playerActivity, content ->// your code here}}}
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.
class MainActivity : AppCompatActivity() {fun showPlayer() {STPlayer.getInstance()?.configuration?.preferredAudioQuality = STAudioQualityEnum.HDSTPlayer.getInstance()?.currentTrackAudioQuality?.observe(this, Observer { quality ->println("current track quality : $quality")})}}
SampleViewController.swiftimport UIKitimport StayTunedSDKclass 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 qualitystaytunedSDK.STPlayer.currentTrackAudioQuality$.subscribe((audioQuality) => {...});
// Coming soon