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 consuming a content offline a user must download a track. The SDK provides the following functions to download and remove a downloaded track.
Android
iOS
Cordova
1
class MainActivity : AppCompatActivity() {
2
3
private fun downloadTrack() {
4
val track = STTrack()
5
STOffline.getInstance()?.add(
6
applicationContext,
7
track,
8
object: STHttpCallback<STTrack> {
9
override fun onSuccess(data: STTrack) {
10
println("success")
11
}
12
13
override fun onError(t: Throwable) {
14
Log.e(LOG_TAG, "Error adding offline content : ${track.key}", t)
15
}
16
}
17
)
18
}
19
20
private fun removeDownload() {
21
val track = STTrack()
22
STOffline.getInstance()?.remove(applicationContext, track)
23
}
24
25
}
Copied!
1
import UIKit
2
import StayTunedSDK
3
4
class SampleViewController: UIViewController {
5
6
private func downloadTrack() {
7
let track = STTrack(/*..*/)
8
STOffline.shared?.add(track, completionHandler: { result in
9
switch result {
10
case .success:
11
print("success")
12
case .failure(let error):
13
print("error: ", error)
14
}
15
})
16
}
17
18
private func removeDownload() {
19
let track = STTrack(/*..*/)
20
STOffline.shared?.remove(track)
21
}
22
23
}
Copied!
1
// Download
2
await STOffline.getInstance().add(track);
3
// Remove a download
4
await STOffline.getInstance().remove(track);
Copied!

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
1
class MainActivity : AppCompatActivity() {
2
3
private fun getDownloadedContents() {
4
STOffline.getInstance()?.contents?.observe(this) { it ->
5
// it is a STContentOfflineItem List
6
}
7
}
8
9
private fun getDownloadedTracks() {
10
STOffline.getInstance()?.tracks?.observe(this) { it ->
11
// it is a STTrackOfflineItem List
12
}
13
}
14
15
}
Copied!
1
import UIKit
2
import StayTunedSDK
3
4
class SampleViewController: UIViewController {
5
6
private func getDownloadedContents() {
7
let offlineContents: [STContentLightOfflineItem] = STOffline.shared?.contetnts
8
}
9
10
private func getDownloadedTracks() {
11
let offlineTracks: [STTrackOfflineItem] = STOffline.shared?.tracks
12
}
13
14
}
Copied!
1
// Get Tracks
2
const trackObserver = STOffline.getInstance()
3
.observeTracks((tracks: STTrackOfflineItem[]) => {
4
// your code
5
});
6
// Stop the observer
7
STOffline.getInstance().removeTrackObserver(trackObserver);
Copied!