/// <summary> /// Provides the value. /// </summary> /// <param name="serviceProvider">The service provider.</param> /// <returns></returns> public object ProvideValue(IServiceProvider serviceProvider) { try { Debug.WriteLine($"Acquiring Vimeo stream source URL from VideoId='{VideoId}'..."); var videoInfoUrl = $"https://player.vimeo.com/video/{VideoId}/config"; using (var client = new HttpClient()) { var videoPageContent = client.GetStringAsync(videoInfoUrl).Result; var videoPageBytes = Encoding.UTF8.GetBytes(videoPageContent); using (var stream = new MemoryStream(videoPageBytes)) { var serializer = new DataContractJsonSerializer(typeof(VimeoVideo)); var metaData = (VimeoVideo)serializer.ReadObject(stream); var files = metaData.request.files.progressive; // Exact match var url = files.OrderByDescending(s => s.width).Select(s => s.url).FirstOrDefault(); Debug.WriteLine($"Stream URL: {url}"); return(VideoSource.FromUri(url)); } } } catch (Exception ex) { Debug.WriteLine("Error occured while attempting to convert Vimeo video ID into a remote stream path."); Debug.WriteLine(ex); } return(null); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value != null) { return(VideoSource.FromUri(value.ToString())); } return(null); }
private void VideoPlayerView_IntroVideoEnded(object sender, EventArgs e) { VideoPlayerView.VideoEnded -= VideoPlayerView_IntroVideoEnded; VideoPlayerView.Source = VideoSource.FromUri(Source); VideoPlayerView.Play(); this.ForceLayout(); VideoPlayerView.VideoEnded += VideoPlayerView_VideoEnded; }
public VideoLezioni(string urlVideo) { InitializeComponent(); var video = urlVideo.Replace(" ", "%20"); urlVideo = Costanti.urlBase + video; videoView.Source = VideoSource.FromUri(urlVideo); //videoView.Source = VideoSource.FromUri("https://amorosoconcorsi.ak12srl.it/services/video/2%20Mcd%20Mcm%20Insiemi%20Numerici-1.mp4"); }
public override object ConvertFromInvariantString(string value) { if (!String.IsNullOrWhiteSpace(value)) { Uri uri; return(Uri.TryCreate(value, UriKind.Absolute, out uri) && uri.Scheme != "file" ? VideoSource.FromUri(value) : VideoSource.FromResource(value)); } throw new InvalidOperationException("Cannot convert null or whitespace to ImageSource"); }
protected override void OnPropertyChanged([CallerMemberName] string propertyName = null) { base.OnPropertyChanged(propertyName); if (propertyName == "IsFullScreen") { ToggleFullScreen(); } if (propertyName == "Anime") { VideoPlayer.Source = VideoSource.FromUri(Anime.Links); } }
public MediaPage(DataStatus status, int inx = 0) { viewing = status; Style = (Style)Application.Current.Resources["backgroundStyle"]; if (status.ExtendMedias[0].Type == "photo") { foreach (var media in status.ExtendMedias) { Children.Add(new ContentPage() { Content = MakeMediaView(media) }); } CurrentPage = Children[inx]; } else { videoView = new VideoPlayer(); if (status.ExtendMedias[0].Type == "animated_gif") { videoView.IsVideoOnly = true; } var gesture = new PanGestureRecognizer(); gesture.PanUpdated += (sender, e) => { switch (e.StatusType) { case GestureStatus.Running: videoView.TranslationX = e.TotalX; videoView.TranslationY = e.TotalY; break; case GestureStatus.Completed: if (Math.Abs(videoView.TranslationY) > (Height / 8)) { App.Navigation.RemovePage(this); } videoView.TranslateTo(0, 0); break; } }; videoView.GestureRecognizers.Add(gesture); Children.Add(new ContentPage() { Content = videoView }); videoView.Source = VideoSource.FromUri(PickVideoVariant(status.ExtendMedias[0].Video.Variants).URL); } }
public VideoPlayerPage(string videoSource) { InitializeComponent(); imageNameLabel.Text = videoSource; if (!String.IsNullOrWhiteSpace(videoSource)) { //videoPlayer.Source = new FileVideoSource //{ // File = videoSource //}; videoPlayer.Source = VideoSource.FromUri("https://archive.org/download/ElephantsDream/ed_hd_512kb.mp4"); } Debug.WriteLine("Playing Video"); }
private void Button_Clicked(object sender, System.EventArgs e) { try { if (input.Text.IndexOf("youtube") != -1) { videoPlayer.Source = VideoSource.FromUri(GetYouTubeUrl(input.Text.Split('=')[1])); } else if (input.Text != "") { videoPlayer.Source = VideoSource.FromUri(input.Text); } } catch (Exception ex) { DisplayAlert("Error", ex.Message, "OK"); } }
async Task ExecuteGetTrueVideoUrlCommand() { if (IsBusy) { return; } IsBusy = true; try { VideoUrl = VideoSource.FromUri(await DataSource.GetTrueVideoUrl(originalVideoUrl)); } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }
/// <summary> /// Provides the value. /// </summary> /// <param name="serviceProvider">The service provider.</param> /// <returns></returns> public object ProvideValue(IServiceProvider serviceProvider) { try { Debug.WriteLine($"Acquiring YouTube stream source URL from VideoId='{VideoId}'..."); var videoInfoUrl = $"https://www.youtube.com/watch?v={VideoId}"; var videoInfos = DownloadUrlResolver.GetDownloadUrls(videoInfoUrl); var video = videoInfos.First(info => info.VideoType == VideoType.Mp4); return(VideoSource.FromUri(video.DownloadUrl)); } catch (Exception ex) { Debug.WriteLine("Error occured while attempting to convert YouTube video ID into a remote stream path."); Debug.WriteLine(ex); } return(null); }
private VideoSource VideoSourceFromType(string videoSource, VideoType videoType) { VideoSource source = null; if (videoType == VideoType.YouTube) { source = YouTubeVideoSourceConstructor(videoSource); } else if (videoType == VideoType.Url) { source = VideoSource.FromUri(videoSource); } else if (videoType == VideoType.Resource) { source = VideoSource.FromResource(videoSource, resourceAssembly); } else if (videoType == VideoType.File) { source = VideoSource.FromFile(videoSource); } return(source); }
async private void InitSource() { CrunchyrollApi.StreamDataResponse res = await crunchyApi.GetStreamData(media.iD); if (res.success) { Console.WriteLine("LOG: SOURCE SUCCESS"); sourceUrl = res.url; videoPlayer.Source = VideoSource.FromUri(res.url); videoPlayer.Position = new TimeSpan(0, 0, res.playhead); } else { if (res.message == "NoStream") { await DisplayAlert("Couldn't get stream", "Media not available, player going to be exited", "OK"); } else { await DisplayAlert("Unknown error", "Unknown error occured, player going to be exited", "OK"); } await Navigation.PopAsync(); } }
/// <summary> /// Provides the value. /// </summary> /// <param name="serviceProvider">The service provider.</param> /// <returns></returns> public object ProvideValue(ref List <eliteVideoQuality> availableQualities, ref eliteVideoQuality currentVideoQuality) { try { Debug.WriteLine($"Acquiring Vimeo stream source URL from VideoId='{VideoId}'..."); var videoInfoUrl = $"https://player.vimeo.com/video/{VideoId}/config"; using (var client = new HttpClient()) { var videoPageContent = client.GetStringAsync(videoInfoUrl).Result; var videoPageBytes = Encoding.UTF8.GetBytes(videoPageContent); using (var stream = new MemoryStream(videoPageBytes)) { var serializer = new DataContractJsonSerializer(typeof(VimeoVideo)); var metaData = (VimeoVideo)serializer.ReadObject(stream); var files = metaData.request.files.progressive; var videoUrl = ""; var videos = files.OrderBy(s => s.width).Select(s => new VideoQualityModel { Quality = s.quality, Url = s.url }).ToList(); var countFlag = 0; foreach (var videoQualityModel in videos) { if (videoQualityModel.Quality.Contains(((int)eliteVideoQuality.Low).ToString())) { availableQualities.Add(eliteVideoQuality.Low); } else if (videoQualityModel.Quality.Contains(((int)eliteVideoQuality.Normal).ToString())) { availableQualities.Add(eliteVideoQuality.Normal); } else if (videoQualityModel.Quality.Contains(((int)eliteVideoQuality.Medium).ToString())) { availableQualities.Add(eliteVideoQuality.Medium); } else if (videoQualityModel.Quality.Contains(((int)eliteVideoQuality.High).ToString())) { availableQualities.Add(eliteVideoQuality.High); } } // Exact match if (videos.Any()) { //try to find preferred quality var prefQuality = videos.FirstOrDefault(v => v.Quality.Contains(VideoQuality.ToString())); if (prefQuality != null) { prefQuality.Quality = Regex.Replace(prefQuality.Quality, "[^0-9]", ""); videoUrl = prefQuality.Url; currentVideoQuality = (eliteVideoQuality)Enum.Parse(typeof(eliteVideoQuality), prefQuality.Quality); return(VideoSource.FromUri(videoUrl)); } //Not found.. Pick first quality in list and expose to caller available qualities videoUrl = videos.First().Url; var finalQuality = Regex.Replace(videos.First().Quality, "[^0-9]", ""); currentVideoQuality = (eliteVideoQuality)Enum.Parse(typeof(eliteVideoQuality), finalQuality); Debug.WriteLine($"Stream URL: {videoUrl}"); //Make sure we can access URL. if (!string.IsNullOrEmpty(videoUrl)) { try { var request = new HttpRequestMessage(HttpMethod.Head, videoUrl); var result = coreSettings.HttpClientSingleton.SendAsync(request).Result; if (!result.IsSuccessStatusCode) { return(null); } } catch { return(null); } } return(VideoSource.FromUri(videoUrl)); } } } } catch (Exception ex) { Debug.WriteLine("Error occured while attempting to convert Vimeo video ID into a remote stream path."); Debug.WriteLine(ex); } return(null); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => VideoSource.FromUri(value as string);
/// <summary> /// Provides the value. /// </summary> /// <param name="serviceProvider">The service provider.</param> /// <returns></returns> public object ProvideValue(IServiceProvider serviceProvider) { try { Debug.WriteLine($"Acquiring YouTube stream source URL from VideoId='{VideoId}'..."); var videoInfoUrl = $"http://www.youtube.com/get_video_info?video_id={VideoId}"; using (var client = new HttpClient()) { var videoPageContent = client.GetStringAsync(videoInfoUrl).Result; var videoParameters = HttpUtility.ParseQueryString(videoPageContent); List <YoutubeStream> streams; var encodedStreamsDelimited = WebUtility.HtmlDecode(videoParameters["url_encoded_fmt_stream_map"]); if (!string.IsNullOrEmpty(encodedStreamsDelimited)) { var encodedStreams = encodedStreamsDelimited.Split(','); var encodedStreamsParsed = encodedStreams.Select(HttpUtility.ParseQueryString); streams = encodedStreamsParsed.Select(x => new YoutubeStream() { mimeType = x["type"], quality = x["quality"], url = x["url"] }).ToList(); } else { var playerResponse = WebUtility.HtmlDecode(videoParameters["player_response"]); var playerResponseObject = JObject.Parse(playerResponse); var streamsList = playerResponseObject["streamingData"]["formats"].ToObject <YoutubeStream[]>(); var adaptiveStreamsList = playerResponseObject["streamingData"]["adaptiveFormats"].ToObject <YoutubeStream[]>(); streams = streamsList.Union(adaptiveStreamsList).ToList(); } var streamsByPriority = streams .OrderBy(s => { var type = s.mimeType; if (type.Contains("video/mp4")) { return(10); } if (type.Contains("video/3gpp")) { return(20); } if (type.Contains("video/x-flv")) { return(30); } if (type.Contains("video/webm")) { return(40); } return(int.MaxValue); }) .ThenBy(s => { var quality = s.quality; return(Array.IndexOf(new[] { "medium", "high", "small" }, quality)); }) .FirstOrDefault(); Debug.WriteLine($"Stream URL: {streamsByPriority.url}"); return(VideoSource.FromUri(streamsByPriority.url)); } } catch (Exception ex) { Debug.WriteLine("Error occured while attempting to convert YouTube video ID into a remote stream path."); Debug.WriteLine(ex); } return(null); }
//templates public void UpdateMediaLayer() { UIMediaContent.Children.Clear(); dynamic media; switch (Post.FileExt) { case "gif": media = WebVeiwTemplate(Post.FileUrl.AbsoluteUri); //UpdateNotification("this is a gif", Color.LightGreen, 2); break; case "webm": //Webm's used to work but dont anymore, hmm media = new VideoPlayer { Source = VideoSource.FromUri(Post.FileUrl), AutoPlay = true, Volume = 0,//Default Mute WidthRequest = Booru.ScreenWidth, //height causes streaching }; Task.Run(async() => { Indicate(); while (((VideoPlayer)media).IsLoading) { if ((((VideoPlayer)media).IsLoading == false)) { Indicate(false); return; } await Task.Delay(100); } ; }); UpdateNotification("Webm's Muted. (volume control not implemented)", Color.LightGreen, 2); break; case "png": case "jpg": case "bmp": media = new Image { Source = ImageSource.FromUri(Post.SampleUrl), HeightRequest = Booru.ScreenHeight / 2, WidthRequest = Booru.ScreenWidth, VerticalOptions = LayoutOptions.Center, }; break; default: media = new Label { Text = $"Media format not implemented: {Post.FileExt}", HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center, TextColor = Color.Chartreuse, }; break; } var result = new StackLayout { //known bug: gif/webView doesn't inherit this background color... BackgroundColor = Color.FromHex("#648F8F8F"), Children = { media }, }; UIMediaContent.Children.Add(result); UIMediaContent.LowerChild(result);//image should be under the menu's }
/// <summary> /// Provides the value. /// </summary> /// <param name="serviceProvider">The service provider.</param> /// <returns></returns> public object ProvideValue(IServiceProvider serviceProvider) { try { Debug.WriteLine($"Acquiring YouTube stream source URL from VideoId='{VideoId}'..."); var videoInfoUrl = $"http://www.youtube.com/get_video_info?video_id={VideoId}"; using (var client = new HttpClient()) { var videoPageContent = client.GetStringAsync(videoInfoUrl).Result; var videoParameters = HttpUtility.ParseQueryString(videoPageContent); var encodedStreamsDelimited = WebUtility.HtmlDecode(videoParameters["url_encoded_fmt_stream_map"]); var encodedStreams = encodedStreamsDelimited.Split(','); var streams = encodedStreams.Select(HttpUtility.ParseQueryString); var streamsByPriority = streams .OrderBy(s => { var type = s["type"]; if (type.Contains("video/mp4")) { return(10); } if (type.Contains("video/3gpp")) { return(20); } if (type.Contains("video/x-flv")) { return(30); } if (type.Contains("video/webm")) { return(40); } return(int.MaxValue); }) .ThenBy(s => { var quality = s["quality"]; switch (Device.Idiom) { case TargetIdiom.Phone: return(Array.IndexOf(new[] { "medium", "high", "small" }, quality)); default: return(Array.IndexOf(new[] { "high", "medium", "small" }, quality)); } }) .FirstOrDefault(); Debug.WriteLine($"Stream URL: {streamsByPriority["url"]}"); return(VideoSource.FromUri(streamsByPriority["url"])); } } catch (Exception ex) { Debug.WriteLine("Error occured while attempting to convert YouTube video ID into a remote stream path."); Debug.WriteLine(ex); } return(null); }
public VideoSource YouTubeVideoSourceConstructor(string videoId) { var videoInfoUrl = $"http://www.youtube.com/get_video_info?video_id={videoId}"; using (var client = new HttpClient()) { client.Timeout = TimeSpan.FromSeconds(3); var videoPageContent = client.GetStringAsync(videoInfoUrl).Result; var videoParameters = HttpUtility.ParseQueryString(videoPageContent); var encodedStreamsDelimited = WebUtility.HtmlDecode(videoParameters["url_encoded_fmt_stream_map"]); var encodedStreams = encodedStreamsDelimited.Split(','); var streams = encodedStreams.Select(HttpUtility.ParseQueryString); var orderedStreams = streams .OrderBy(s => { var type = s["type"]; if (type.Contains("video/mp4")) { return(10); } if (type.Contains("video/3gpp")) { return(20); } if (type.Contains("video/x-flv")) { return(30); } if (type.Contains("video/webm")) { return(40); } return(int.MaxValue); }) .ThenBy(s => { var quality = s["quality"]; int i = 0; switch (Device.Idiom) { case TargetIdiom.Phone: i = Array.IndexOf(new[] { "hd720", "medium", "high", "small" }, quality); break; default: i = Array.IndexOf(new[] { "high", "medium", "small" }, quality); break; } return(i); // i >= 0 ? i : Int32.MaxValue; }); var streamsByPriority = orderedStreams.FirstOrDefault(); return(VideoSource.FromUri(streamsByPriority["url"])); } }