Skip to content

Commit 6699681

Browse files
Update hls-downloader.md
1 parent 269fd8e commit 6699681

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

hls-downloader.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Using iOS HLS Downloader
2+
3+
HISPlayer iOS for Unity can download an HLS stream and, once it has been downloaded, play it as [**local content**](./local-files.md).
4+
5+
For this actions iOS device doesn't need to ask for permissions.
6+
7+
# Download the HLS stream.
8+
To download the HLS stream, first call the **DownloadStream** API. The stream will be saved in your [**Persistent Data Path**](./local-files.md#Persistent-Data-Path):
9+
10+
```C#
11+
public class HISPlayeriOSDownloaderSample : HISPlayerManager
12+
{
13+
protected void DownloadStream()
14+
{
15+
DownloadStream("https://MyHLSStreamURL.m3u8", "MyStreamTitle");
16+
}
17+
}
18+
```
19+
You can track the progress of the HLS download by overriding the function **EventOnDownloadProgress**.
20+
21+
```C#
22+
public class HISPlayeriOSDownloaderSample : HISPlayerManager
23+
{
24+
protected override void EventOnDownloadCompleted(HISPlayerEventInfo eventInfo)
25+
{
26+
// 1. Prepare the StreamProperties to be added
27+
StreamProperties stream = new StreamProperties();
28+
stream.renderMode = HISPlayerRenderMode.RawImage;
29+
stream.rawImage = rawImage1;
30+
stream.autoPlay = true;
31+
32+
// 2. Add prepared stream
33+
AddStream(stream);
34+
35+
// 3. Add the downloaded video content to the stream. eventInfo.stringInfo corresponds to
36+
// the relative path to the Application.PersistentDataPath. You can save this value to
37+
// open the content at any point after this event has been triggered
38+
AddVideoContent(totalScreens, eventInfo.stringInfo);
39+
totalScreens++;
40+
41+
base.EventOnDownloadCompleted(eventInfo);
42+
}
43+
}
44+
```
45+
46+
# Play the downloaded video
47+
48+
Override the **EventOnDownloadCompleted**. This overrided function will be called when the stream has finished downloading. You can use it to directly start the video playback or decide to playback the video later at any given time.
49+
To start playing the video, just input the previously settled stream's title, and HISPlayer will automatically find the video in your [**Persistent Data Path**](./local-files.md#Persistent-Data-Path).
50+
51+
Here is an example of how this event could be used to play the stream just after it has finished downloading:
52+
53+
```C#
54+
public class HISPlayeriOSDownloaderSample : HISPlayerManager
55+
{
56+
protected override void EventOnDownloadProgress(HISPlayerEventInfo eventInfo)
57+
{
58+
// Change Downloading Stream text
59+
if (eventInfo.stringInfo == "MyStreamTitle")
60+
Debug.Log("Downloading Stream: " + eventInfo.param1 + "%. Stream Title: " + eventInfo.stringInfo + ".");
61+
62+
}
63+
}
64+
```
65+
66+
# Delete downloaded HLS Streams from iOS device
67+
68+
To delete a specific downloaded HLS stream from [**Persistent Data Path**](./local-files.md#Persistent-Data-Path) (application's path), use the **DeleteDownloadedStream** API:
69+
70+
```C#
71+
public class HISPlayeriOSDownloaderSample : HISPlayerManager
72+
{
73+
protected void DeleteDownloadedStreamFunction(string streamTitle)
74+
{
75+
DeleteDownloadedStream(streamTitle);
76+
}
77+
}
78+
```
79+
To delete all streams from the [**Persistent Data Path**](./local-files.md#Persistent-Data-Path), use the **DeleteAllDownloadedStreams** API:
80+
81+
```C#
82+
public class HISPlayeriOSDownloaderSample : HISPlayerManager
83+
{
84+
protected void DeleteAllDownloadedStreamFunction()
85+
{
86+
DeleteAllDownloadedStreams();
87+
}
88+
}
89+
```

0 commit comments

Comments
 (0)