Make your content available offline

Staytuned SDK enables your users to download content on their devices to consume it offline.

This feature is not available on the web platform

Download and remove a downloaded track

Before using a content a user must download a track. The SDK provides the following functions to download and remove a downloaded track.

Android
iOS
Cordova
Android
class MainActivity : AppCompatActivity() {
private fun downloadTrack() {
val track = STTrack()
STOffline.getInstance()?.add(
applicationContext,
track,
object: STHttpCallback<STTrack> {
override fun onSuccess(data: STTrack) {
println("success")
}
override fun onError(error: Throwable) {
println(error)
}
}
)
}
private fun removeDownload() {
val track = STTrack()
STOffline.getInstance()?.remove(applicationContext, track)
}
}
iOS
import UIKit
import StayTunedSDK
class SampleViewController: UIViewController {
private func downloadTrack() {
let track = STTrack(/*..*/)
STOffline.shared?.add(track, completionHandler: { result in
switch result {
case .success:
print("success")
case .failure(let error):
print("error: ", error)
}
})
}
private func removeDownload() {
let track = STTrack(/*..*/)
STOffline.shared?.remove(track)
}
}
Cordova
// Download
await STOffline.getInstance().add(track);
// Remove a download
await STOffline.getInstance().remove(track);

List the downloaded contents and tracks

You can access the downloaded content as follow. Please see the API REFERENCE for more details on models.

Android
iOS
Cordova
Android
class MainActivity : AppCompatActivity() {
private fun getDownloadedContents() {
STOffline.getInstance()?.contents?.observe(this) { it ->
// it is a STContentOfflineItem List
}
}
private fun getDownloadedTracks() {
STOffline.getInstance()?.tracks?.observe(this) { it ->
// it is a STTrackOfflineItem List
}
}
}
iOS
import UIKit
import StayTunedSDK
class SampleViewController: UIViewController {
private func getDownloadedContents() {
// TODO
}
private func getDownloadedTracks() {
// TODO
}
}
Cordova
// Get Tracks
const trackObserver = STOffline.getInstance()
.observeTracks((tracks: STTrackOfflineItem[]) => {
// your code
});
// Stop the observer
STOffline.getInstance().removeTrackObserver(trackObserver);