void UpdateSource() { if (Element.Source != null) { AVAsset asset = null; var uriSource = Element.Source as UriMediaSource; if (uriSource != null) { if (uriSource.Uri.Scheme == "ms-appx") { if (uriSource.Uri.LocalPath.Length <= 1) { return; } // used for a file embedded in the application package asset = AVAsset.FromUrl(NSUrl.FromFilename(uriSource.Uri.LocalPath.Substring(1))); } else if (uriSource.Uri.Scheme == "ms-appdata") { string filePath = Platform.ResolveMsAppDataUri(uriSource.Uri); if (string.IsNullOrEmpty(filePath)) { throw new ArgumentException("Invalid Uri", "Source"); } asset = AVAsset.FromUrl(NSUrl.FromFilename(filePath)); } else { asset = AVUrlAsset.Create(NSUrl.FromString(uriSource.Uri.AbsoluteUri)); } } else { var fileSource = Element.Source as FileMediaSource; if (fileSource != null) { asset = AVAsset.FromUrl(NSUrl.FromFilename(fileSource.File)); } } var item = new AVPlayerItem(asset); RemoveStatusObserver(); _statusObserver = (NSObject)item.AddObserver("status", NSKeyValueObservingOptions.New, ObserveStatus); if (_avPlayerViewController.Player != null) { _avPlayerViewController.Player.ReplaceCurrentItemWithPlayerItem(item); } else { _avPlayerViewController.Player = new AVPlayer(item); _rateObserver = (NSObject)_avPlayerViewController.Player.AddObserver("rate", NSKeyValueObservingOptions.New, ObserveRate); } if (Element.AutoPlay) { Play(); } } else { if (Element.CurrentState == MediaElementState.Playing || Element.CurrentState == MediaElementState.Buffering) { _avPlayerViewController.Player.Pause(); Controller.CurrentState = MediaElementState.Stopped; } } }