/// Triggers the initial AVAssetDownloadTask for a given Asset. public void DownloadAsset(MusicAsset asset) { // For the initial download, we ask the URLSession for an AVAssetDownloadTask // with a minimum bitrate corresponding with one of the lower bitrate variants // in the asset. // TODO: workaround for bug https://bugzilla.xamarin.com/show_bug.cgi?id=44201 to get it to build in Mobile Center var taskOptions = new NSDictionary(new NSString("AVAssetDownloadTaskMinimumRequiredMediaBitrateKey"), new NSNumber(265000)); // should be this // var taskOptions = new AVAssetDownloadOptions { MinimumRequiredMediaBitrate = 265000 }; var task = assetDownloadURLSession.GetAssetDownloadTask(asset.UrlAsset, asset.Id, null, taskOptions); // To better track the AVAssetDownloadTask we set the taskDescription to something unique for our sample. task.TaskDescription = asset.Id; activeDownloadsMap [task] = asset; task.Resume(); AssetDownloadStateChanged?.Invoke(this, new MusicAssetDownloadStateChangeArgs(asset.Music, MusicAssetDownloadState.Downloading)); }
internal void DownloadAssetStream(Asset asset) { // Get the default media selections for the asset's media selection groups. var preferredMediaSelection = asset.UrlAsset.PreferredMediaSelection; ///* // Creates and initializes an AVAggregateAssetDownloadTask to download multiple AVMediaSelections // on an AVURLAsset. // For the initial download, we ask the URLSession for an AVAssetDownloadTask with a minimum bitrate // corresponding with one of the lower bitrate variants in the asset. // */ AVAggregateAssetDownloadTask task = null; try { var dictionary = new NSDictionary <NSString, NSObject>(new NSString("AVAssetDownloadTaskMinimumRequiredMediaBitrateKey"), (NSObject)(new NSNumber(265_000))); task = assetDownloadUrlSession.GetAssetDownloadTask(asset.UrlAsset, new AVMediaSelection[] { preferredMediaSelection }, asset.Stream.Name, null, dictionary); task.TaskDescription = asset.Stream.Name; activeDownloadsMap.Add(task, asset); task.Resume(); var userInfo = new Dictionary <string, object>(); userInfo[Asset.Keys.Name] = asset.Stream.Name; userInfo[Asset.Keys.DownloadState] = AssetDownloadState.Downloading.ToString(); userInfo[Asset.Keys.DownloadSelectionDisplayName] = GetDisplayNamesForSelectedMediaOptions(preferredMediaSelection); var userInfoDictionary = NSDictionary.FromObjectsAndKeys(userInfo.Values.ToArray(), userInfo.Keys.ToArray()); NSNotificationCenter.DefaultCenter.PostNotificationName(AssetPersistenceManager.AssetDownloadStateChanged, null, userInfoDictionary); } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
/// Triggers the initial AVAssetDownloadTask for a given Asset. public void DownloadAsset(MusicAsset asset) { Track.Download(asset.Music); // For the initial download, we ask the URLSession for an AVAssetDownloadTask // with a minimum bitrate corresponding with one of the lower bitrate variants in the asset. var taskOptions = new AVAssetDownloadOptions { MinimumRequiredMediaBitrate = 265000 }; var task = assetDownloadURLSession.GetAssetDownloadTask(asset.UrlAsset, asset.Id, null, taskOptions); // To better track the AVAssetDownloadTask we set the taskDescription to something unique for our sample. task.TaskDescription = asset.Id; activeDownloadsMap [task] = asset; task.Resume(); AssetDownloadStateChanged?.Invoke(this, new MusicAssetDownloadStateChangeArgs(asset.Music, MusicAssetDownloadState.Downloading)); }