/// <summary> /// This method is invoked when the MediaCache has downloaded several video and audio chunks for the asset /// associated with the manifestUri. The progress value is defined with value percent. /// From this method it's possible to monitor the download of the video and audio chunks. /// </summary> private void Cache_DownloadProgress(MediaCache sender, Uri manifestUri, uint percent) { ulong duration = mediaCache.GetDuration(manifestUri) / 10000000; LogMessage("Download progress: " + percent.ToString() + "%" + " Download bitrate: " + sender.GetCurrentBitrate(manifestUri).ToString() + "b/s " + " Audio chunks: " + sender.GetSavedAudioChunksCount(manifestUri).ToString() + "/" + sender.GetAudioChunksCount(manifestUri).ToString() + " Video chunks: " + sender.GetSavedVideoChunksCount(manifestUri).ToString() + "/" + sender.GetVideoChunksCount(manifestUri).ToString() + " Size on disk: " + sender.GetCurrentMediaCacheSize(manifestUri).ToString() + "/" + sender.GetExpectedSize(manifestUri).ToString() + " Remaining time: " + sender.GetRemainingDowloadTime(manifestUri).ToString() + " seconds " + " Asset duration: " + duration.ToString() + " seconds " + " for manifest: " + manifestUri.ToString()); }
/// <summary> /// This method is invoked when the status of an asset in the MediaCache has changed. /// Parameter: The status of the asset: /// - Initialized /// - DownloadingManifest /// - ManifestDownloaded /// - DownloadingChunks /// - AssetPlayable (for Progressive Download only - Not applicable for DownloadToGo) /// - ChunksDownloaded /// - Errorxxxxx /// </summary> private async void Cache_StatusProgress(MediaCache sender, Uri manifestUri, AssetStatus assetStatus) { LogMessage("Download status: " + assetStatus.ToString() + " for manifest: " + manifestUri.ToString()); await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () => { if (assetStatus == AssetStatus.ChunksDownloaded) { // if the asset is fully downloaded and the asset is protected with PlayReady, the PlayReady License can be acquired. // The PlayReady License is automatically acquired by the MediaCache after calling mediaCache.StartDownload // The step below is normally not required for persistent license if (mediaCache.IsAssetProtected(manifestUri)) { LogMessage("As the downloaded content is protected License Acquisition required, LicenseUrl: " + (!string.IsNullOrEmpty(PlayReadyLicenseUrl) ? PlayReadyLicenseUrl : "null") + " CustomData: " + PlayReadyChallengeCustomData); bool result = await mediaCache.GetPlayReadyLicense(manifestUri, (!string.IsNullOrEmpty(PlayReadyLicenseUrl) ? new Uri(PlayReadyLicenseUrl) : null), PlayReadyChallengeCustomData); if (result == true) LogMessage("Acquisition License successful"); else LogMessage("Acquisition License failed"); } } UpdateControls(); }); }
/// <summary> /// This method initialize the Media Cache /// </summary> private async System.Threading.Tasks.Task<bool> InitializeCache() { bool result = false; if (mediaCache != null) { mediaCache.StatusProgressEvent -= Cache_StatusProgress; mediaCache.DownloadProgressEvent -= Cache_DownloadProgress; mediaCache = null; } // // Create the Media Cache to download Smooth Streaming Asset // mediaCache = new MediaCache(); if (mediaCache != null) { // // Initialize the Media Cache // // "AssetCache" is the name of the directory in the Isolated Storage where the video and audio chunks will be recorded // Max Download Session = 5, it's the maximum number of simultaneous download session // Max Memory Buffer size = 64 MB, it's the maximum size of the memory buffer, when the buffer size is over this limit the video and audio chunks will be stored in the isolated storage // Max Downloaded Assets = 100, the maximum number of assets which can be stored on disk // Max Error = 20, when the number of http error is over this limit, the download thread associated with the asset is cancelled // AutoStartDownload, if true the download thread will start automatically after a resume // result = await mediaCache.Initialize("AssetsCache", // Max Download Session 5, // Max Memory buffer Size per session 256000, // Max downloaded Assets 100, // Max Error 20, //AutoStartDownload // Set Auto start download when launching the application // The download thread will be automatically launched if the asset is not completely downloaded true ); if (result) { mediaCache.StatusProgressEvent += Cache_StatusProgress; mediaCache.DownloadProgressEvent += Cache_DownloadProgress; ulong asize = await mediaCache.GetAvailableSize(); ulong csize = await mediaCache.GetCacheSize(); LogMessage("Cache Initialized"); LogMessage("Cache available size: " + asize.ToString() + " Bytes"); LogMessage("Cache current size: " + csize.ToString() + " Bytes"); } } return result; }