|
| 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 | + // Change Downloading Stream text |
| 27 | + if (eventInfo.stringInfo == "MyStreamTitle") |
| 28 | + Debug.Log("Downloading Stream: " + eventInfo.param1 + "%. Stream Title: " + eventInfo.stringInfo + "."); |
| 29 | + } |
| 30 | +} |
| 31 | +``` |
| 32 | + |
| 33 | +# Play the downloaded video |
| 34 | + |
| 35 | +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. |
| 36 | +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). |
| 37 | + |
| 38 | +Here is an example of how this event could be used to play the stream just after it has finished downloading: |
| 39 | + |
| 40 | +```C# |
| 41 | +public class HISPlayeriOSDownloaderSample : HISPlayerManager |
| 42 | +{ |
| 43 | + protected override void EventOnDownloadProgress(HISPlayerEventInfo eventInfo) |
| 44 | + { |
| 45 | + // 1. Prepare the StreamProperties to be added |
| 46 | + StreamProperties stream = new StreamProperties(); |
| 47 | + stream.renderMode = HISPlayerRenderMode.RawImage; |
| 48 | + stream.rawImage = rawImage1; |
| 49 | + stream.autoPlay = true; |
| 50 | + |
| 51 | + // 2. Add prepared stream |
| 52 | + AddStream(stream); |
| 53 | + |
| 54 | + // 3. Add the downloaded video content to the stream. eventInfo.stringInfo corresponds to |
| 55 | + // the relative path to the Application.PersistentDataPath. You can save this value to |
| 56 | + // open the content at any point after this event has been triggered |
| 57 | + AddVideoContent(totalScreens, eventInfo.stringInfo); |
| 58 | + totalScreens++; |
| 59 | + |
| 60 | + base.EventOnDownloadCompleted(eventInfo); |
| 61 | + } |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +# Delete downloaded HLS Streams from iOS device |
| 66 | + |
| 67 | +To delete a specific downloaded HLS stream from [**Persistent Data Path**](./local-files.md#Persistent-Data-Path) (application's path), use the **DeleteDownloadedStream** API: |
| 68 | + |
| 69 | +```C# |
| 70 | +public class HISPlayeriOSDownloaderSample : HISPlayerManager |
| 71 | +{ |
| 72 | + protected void DeleteDownloadedStreamFunction(string streamTitle) |
| 73 | + { |
| 74 | + DeleteDownloadedStream(streamTitle); |
| 75 | + } |
| 76 | +} |
| 77 | +``` |
| 78 | +To delete all streams from the [**Persistent Data Path**](./local-files.md#Persistent-Data-Path), use the **DeleteAllDownloadedStreams** API: |
| 79 | + |
| 80 | +```C# |
| 81 | +public class HISPlayeriOSDownloaderSample : HISPlayerManager |
| 82 | +{ |
| 83 | + protected void DeleteAllDownloadedStreamFunction() |
| 84 | + { |
| 85 | + DeleteAllDownloadedStreams(); |
| 86 | + } |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +# Related API |
| 91 | + |
| 92 | +### Event and Virtual Options |
| 93 | + |
| 94 | +* **public enum HISPlayerEvent**: The list of events provided by HISPlayer SDK for using HLS Downloader functionalities. The events can be used with the virtual functions in the next section: |
| 95 | + * **HISPLAYER_EVENT_DOWNLOAD_COMPLETED** |
| 96 | + * **HISPLAYER_EVENT_DOWNLOAD_PROGRESS** |
| 97 | +#### protected virtual void EventOnDownloadCompleted(HISPlayerEventInfo eventInfo) |
| 98 | +Override this method to add custom logic when **HISPlayerEvent.HISPLAYER_EVENT_DOWNLOAD_COMPLETED** is triggered. |
| 99 | +This event occurs whenever a stream that was being downloaded has ended the download process, and it's ready to be played. |
| 100 | + |
| 101 | +<table> |
| 102 | + <tr> |
| 103 | + <th>Name</th> |
| 104 | + <th>Description</th> |
| 105 | + </tr> |
| 106 | + <tr> |
| 107 | + <td>stringInfo</td> |
| 108 | + <td>Relative path where the stream has been stored. This will equal to the title settled to the video. The path is relative to the Application.persistentDataPath,which in iOS corresponds to /var/mobile/Containers/Data/Application/<guid>/Documents. Save it for later plaback of such stream.</td> |
| 109 | + </tr> |
| 110 | +</table> |
| 111 | + |
| 112 | +#### protected virtual void EventOnDownloadProgress(HISPlayerEventInfo eventInfo) |
| 113 | +Override this method to add custom logic when **HISPlayerEvent.HISPLAYER_EVENT_DOWNLOAD_PROGRESS** is triggered. |
| 114 | +This event occurs whenever a HLS stream is being downloaded, to retrieve the progress of such download. |
| 115 | + |
| 116 | +<table> |
| 117 | + <tr> |
| 118 | + <th>Name</th> |
| 119 | + <th>Description</th> |
| 120 | + </tr> |
| 121 | + <tr> |
| 122 | + <td>param1</td> |
| 123 | + <td>The percentage of the download progress of a certain stream.</td> |
| 124 | + </tr> |
| 125 | + <tr> |
| 126 | + <td>stringInfo</td> |
| 127 | + <td>Title of the stream that is being downloaded. This title is settled by the user when calling the DownloadStream API.</td> |
| 128 | + </tr> |
| 129 | +</table> |
| 130 | + |
| 131 | +### Non-virtual Functions |
| 132 | + |
| 133 | +#### public void DownloadStream(string url, string videoTitle) |
| 134 | +Download an HLS Stream. Stream will be automatically saved on the Application.PersisentDataPath (/var/mobile/Containers/Data/Appligation/<guid>/Documents). If 2 downloaded contents have the same video title, the last one will overrite the first one. Avoid using non english characters, dots, slashes and any other kind of special character. The **url** refers to the URL to the HLS stream. **videoTitle** is the name of the saved stream and will allow to reproduce it once it has been downloaded. |
| 135 | + |
| 136 | +#### public void DeleteDownloadStream(string videoTitle) |
| 137 | +Delete a specific downloaded HLS Stream. **videoTitle** is the name of the stream that will be deleted from the device. |
| 138 | + |
| 139 | +#### public void DeleteAllDownloadedStreams() |
| 140 | +Delete all downloaded streams that have been stored in the Application.PersistentDataPath. |
0 commit comments