/// <summary> /// Populates the page with content passed during navigation. Any saved state is also /// provided when recreating a page from a prior session. /// </summary> /// <param name="sender"> /// The source of the event; typically <see cref="NavigationHelper"/> /// </param> /// <param name="e">Event data that provides both the navigation parameter passed to /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and /// a dictionary of state preserved by this page during an earlier /// session. The state will be null the first time a page is visited.</param> private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e) { // TODO: Create an appropriate data model for your problem domain to replace the sample data try { var video = (Video)e.NavigationParameter; var channelVids = await ChannelDataSource.GetChannelAsync(video.ChannelId); this.defaultViewModel["Channel"] = new IncrementalVideos(video.ChannelId); this.DefaultViewModel["Item"] = video; string videoId = video.Id; this.VideoId = videoId; var url = await YouTube.GetVideoUriAsync(videoId, Settings.VideoQuality); if (url != null) { this.mediaPlayer.Source = url.Uri; this.mediaPlayer.Pause(); } } catch { pageTitle.Text = "Video Didn't Load"; } if (VideoId != null) { SetPlayerSize(); } Window.Current.SizeChanged += OnWindowSizeChanged; }
protected override async void OnNavigatedTo(NavigationEventArgs e) { try { if (NetworkInterface.GetIsNetworkAvailable()) { player.Visibility = Visibility.Collapsed; progress.Visibility = Visibility.Visible; string videoId = String.Empty; YoutubeVideo video = e.Parameter as YoutubeVideo; if (video != null && !video.Id.Equals(String.Empty)) { //Get The Video Uri and set it as a player source var url = await YouTube.GetVideoUriAsync(video.Id, YouTubeQuality.Quality480P); player.Source = url.Uri; } player.Visibility = Visibility.Visible; progress.Visibility = Visibility.Collapsed; } else { MessageDialog message = new MessageDialog("You're not connected to Internet!"); await message.ShowAsync(); this.Frame.GoBack(); } } catch { } base.OnNavigatedTo(e); }
protected async override void OnNavigatedTo(NavigationEventArgs e) { try { if (NetworkInterface.GetIsNetworkAvailable()) { string videoId = String.Empty; if (NavigationContext.QueryString.TryGetValue("videoId", out videoId)) { //Get The Video Uri and set it as a player source var url = await YouTube.GetVideoUriAsync(videoId, YouTubeQuality.Quality480P); player.Source = url.Uri; } } else { MessageBox.Show("You're not connected to Internet!"); NavigationService.GoBack(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } base.OnNavigatedTo(e); }
/// <summary> /// Populates the page with content passed during navigation. Any saved state is also /// provided when recreating a page from a prior session. /// </summary> /// <param name="sender"> /// The source of the event; typically <see cref="NavigationHelper"/> /// </param> /// <param name="e">Event data that provides both the navigation parameter passed to /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and /// a dictionary of state preserved by this page during an earlier /// session. The state will be null the first time a page is visited.</param> private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e) { try { if (NetworkInterface.GetIsNetworkAvailable()) { player.Visibility = Visibility.Collapsed; progress.Visibility = Visibility.Visible; string videoId = String.Empty; YoutubeVideo video = e.NavigationParameter as YoutubeVideo; if (video != null && !video.Id.Equals(String.Empty)) { //Get The Video Uri and set it as a player source var url = await YouTube.GetVideoUriAsync(video.Id, YouTubeQuality.Quality1080P); player.Source = url.Uri; } player.Visibility = Visibility.Visible; progress.Visibility = Visibility.Collapsed; } else { MessageDialog message = new MessageDialog("İnternet bağlantınızda sorun var, lütfen internet bağlantınızı kontrol edin ve tekrar deneyin."); await message.ShowAsync(); this.Frame.GoBack(); } } catch { } }
protected async override void OnNavigatedTo(NavigationEventArgs e) { try { if (NetworkInterface.GetIsNetworkAvailable()) { video = e.Parameter as Video; var Url = await YouTube.GetVideoUriAsync(video.Id, YouTubeQuality.QualityLow); Player.Source = Url.Uri; Player.Play(); } else { MessageDialog message = new MessageDialog("You are not connected to Internet"); await message.ShowAsync(); this.Frame.GoBack(); } } catch { } base.OnNavigatedTo(e); }
/// <summary> /// <summary> /// アイテムをタップしたとき /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void itemGridView_Tapped(object sender, TappedRoutedEventArgs e) { var item = (sender as GridView).SelectedItem; if (item == null) { return; } vm.Current = item as Video; MainPage.SelectItemIndex = (sender as GridView).SelectedIndex; var uri = new Uri(vm.Current.Url); if (vm.GoIE == true) { await Launcher.LaunchUriAsync(uri); } else { try { var url = await YouTube.GetVideoUriAsync(vm.Current.VidoId, YouTubeQuality.Quality1080P); this.media.AutoPlay = true; this.media.Source = url.Uri; this.media.Play(); } catch { } } }
public VideoDetailItem() { this.InitializeComponent(); if (player != null && player.CurrentState.ToString() == "Playing") { player.Stop(); } this.DataContextChanged += async(s, e) => { //Get The Video Uri and set it as a player source var Item = this.DataContext as Model.Video; if (Item != null && !Item.Id.Equals(String.Empty)) { try { var url = await YouTube.GetVideoUriAsync(Item.Id, YouTubeQuality.Quality480P); player.Source = url.Uri; this.Bindings.Update(); } catch (YouTubeUriNotFoundException _e) { Debug.WriteLine(_e.Message); MessageDialog message = new MessageDialog("This video is not availible, please select other"); await message.ShowAsync(); } } }; }
/// <summary> /// Tries to get a youtube link from a post. If it fails /// it returns null. /// </summary> /// <param name="post"></param> /// <returns></returns> private static async Task <YouTubeUri> GetYouTubeVideoUrl(Post post) { if (String.IsNullOrWhiteSpace(post.Url)) { return(null); } try { // Try to find the ID string youtubeVideoId = TryToGetYouTubeId(post); if (!String.IsNullOrWhiteSpace(youtubeVideoId)) { // We found it! // #todo make this quality an option dependent on device! return(await YouTube.GetVideoUriAsync(youtubeVideoId, YouTubeQuality.QualityMedium)); } } catch (Exception) { App.BaconMan.TelemetryMan.ReportEvent("YoutubeString", "Failed to find youtube video"); } return(null); }
public async void GetVideoYoutubeSource(string id, MediaElement media, TextBlock RequestUrl, TextBlock TypeVideo) { try { var videoSource = await YouTube.GetVideoUriAsync(id, YouTubeQuality.Quality720P); if (videoSource.Uri != null) { media.Source = videoSource.Uri; RequestUrl.Text = videoSource.Uri.ToString(); TypeVideo.Text = GetTypeYoutube(videoSource.Itag); media.Play(); } else { var dialog = new MessageDialog("Couldn't get link from youtube"); await dialog.ShowAsync(); } } catch (Exception) { var dialog = new MessageDialog("Could not play this video in your country!"); await dialog.ShowAsync(); } }
private async void OnPlayYouTubeVideo(object sender, RoutedEventArgs e) { try { Progress.IsActive = true; var uri = await YouTube.GetVideoUriAsync(YouTubeIdBox.Text, YouTubeQuality.Quality720P); if (uri != null) { YouTubePlayer.Source = uri.Uri; YouTubePlayer.Play(); } else { Debugger.Break(); // TODO: Show error message (no video uri found) Progress.IsActive = false; } } catch (Exception exception) { // TODO: Add exception handling Debugger.Break(); Progress.IsActive = false; } }
public async Task When_loading_PQVlW4xbNuI_then_correct_uris_are_returned() { //// Arrange var youTubeId = "PQVlW4xbNuI"; //// Act var allUris = await YouTube.GetUrisAsync(youTubeId); var uri720P = await YouTube.GetVideoUriAsync(youTubeId, YouTubeQuality.Quality480P, YouTubeQuality.Quality720P); var has480P = false; try { var uri480P = await YouTube.GetVideoUriAsync(youTubeId, YouTubeQuality.Quality480P, YouTubeQuality.Quality480P); has480P = true; } catch (Exception) { } //// Assert Assert.IsTrue(allUris.Any(u => u.VideoQuality == YouTubeQuality.Quality480P && !u.HasAudio)); Assert.IsFalse(allUris.Any(u => u.VideoQuality == YouTubeQuality.Quality480P && u.HasAudio)); Assert.IsFalse(has480P); //// No 480p stream with audio available Assert.IsNotNull(uri720P); //// 720p stream with audio available Assert.AreEqual(YouTubeQuality.Quality720P, uri720P.VideoQuality); }
private async void OnPlay(object o, RoutedEventArgs routedEventArgs) { var youTubeId = YouTubeTextBox.Text; try { //// TODO: Show progress bar var uri = await YouTube.GetVideoUriAsync(youTubeId, YouTubeQuality.Quality1080P); if (uri != null) { // @"MICROSOFTVIDEO://www.example.com/myFile.wmv"; //var options = new LauncherOptions(); //options.ContentType = "video/mp4"; //await Launcher.LaunchUriAsync(uri.Uri, options); var player = BackgroundMediaPlayer.Current; player.SetUriSource(uri.Uri); player.Play(); } else { throw new Exception("no_video_urls_found"); } } catch (Exception exception) { //// TODO: Show exception } finally { //// TODO: Hide progress bar } }
private async void LoadVideo(String vidurl) { var url = await YouTube.GetVideoUriAsync(vidurl, YouTubeQuality.Quality480P); mediaYoutube.Source = url.Uri; mediaYoutube.AutoPlay = false; }
/// <summary> /// Starts loading the feed and parse the response. /// </summary> /// <returns></returns> public async Task <IEnumerable <YouTubeSchema> > Load() { string xmlContent = await DownloadAsync(_uri); var atoms = XNamespace.Get("http://www.w3.org/2005/Atom"); var medians = XNamespace.Get("http://search.yahoo.com/mrss/"); var doc = XDocument.Parse(xmlContent); var result = (from entry in doc.Descendants(atoms.GetName("entry")) select new YouTubeSchema() { Title = GetYouTubeTitle(atoms, entry, medians), Summary = GetYouTubeSummary(atoms, entry, medians), VideoUrl = GetVideoUrl(atoms, entry), ImageUrl = entry.Descendants(medians.GetName("thumbnail")).Select(thumbnail => thumbnail.Attribute("url").Value).FirstOrDefault() }).ToArray(); foreach (var item in result) { item.MediaUrl = (await YouTube.GetVideoUriAsync(item.VideoId, YouTubeQuality.Unknown)).Uri.ToString(); } return(result); }
protected async void youtubevideo2(string id) { try { ProgressProgressBar2.IsEnabled = true; var uri = await YouTube.GetVideoUriAsync(id, YouTubeQuality.Quality720P); // “JPF_iD1IXyc” video id from youtube video link if (uri != null) { YouTubePlayerMediaElement2.Source = uri.Uri; YouTubePlayerMediaElement2.Play(); // YouTubePlayerMediaElement.Source = uri.Uri; // YouTubePlayerMediaElement.Play(); } else { Debugger.Break(); // TODO: Show error message (no video uri found) ProgressProgressBar.IsEnabled = false; } } catch (Exception exception) { // TODO: Add exception handling Debugger.Break(); ProgressProgressBar.IsEnabled = false; } }
//Method to load the youtube video on the mainpage private async void LoadVideo() { string videoSource = txtVideoSource.Text; var url = await YouTube.GetVideoUriAsync(videoSource, YouTubeQuality.Quality480P); mediaYoutube.Source = url.Uri; mediaYoutube.AutoPlay = false; }
protected async override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); Models.Video video = e.Parameter as Models.Video; var Url = await YouTube.GetVideoUriAsync(video.Id, YouTubeQuality.Quality720P); Player.Source = Url.Uri; }
private async void Button_Click_1(object sender, RoutedEventArgs e) { var url = await YouTube.GetVideoUriAsync(GetYouTubeID(((Button)sender).Tag.ToString()), YouTubeQuality.Quality480P); //var player = new MediaElement(); //..Source = url.Uri; //Player.Play(); }
public static async Task <Uri> GetVideo(Movie m) { string id = await GetVidID(m.Name, m.Year.ToString()); var url = await YouTube.GetVideoUriAsync(id, YouTubeQuality.Quality480P); return(url.Uri); }
protected async override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); video = e.Parameter as XemYoutube.Video_youtube; var Url = await YouTube.GetVideoUriAsync(video.Id, YouTubeQuality.Quality1080P); Player.Source = Url.Uri; }
private async void Img_Tapped(object sender, TappedRoutedEventArgs e) { // System.Uri Mediauri = new System.Uri(TextBoxURLPath.Text); var Mediauri = await YouTube.GetVideoUriAsync(YoutubeId, YouTubeQuality.NotAvailable); MyMedia.Source = Mediauri.Uri; MyMedia.Play(); }
protected async override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); DataPage datapage = e.Parameter as DataPage; // id = e.Parameter as String; var Url = await YouTube.GetVideoUriAsync(datapage.idVideo, YouTubeQuality.Quality1080P); Player.Source = Url.Uri; idchannel = datapage.idChannel; }
private async Task <YouTubeUri> GetYouTubeYriForControl(string url) { string pattern = @"(embed\/[-A-Za-z0-9]+)"; var regex = new Regex(pattern, RegexOptions.Compiled | RegexOptions.Multiline); var clearUrl = regex.Match(url); string path = clearUrl.ToString().Replace("embed/", ""); var pathUri = await YouTube.GetVideoUriAsync(path, YouTubeQuality.Quality360P); return(pathUri); }
protected async override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); try { video = e.Parameter as XemYouTubeThoi.Model.Video; var Url = await YouTube.GetVideoUriAsync(video.Id, YouTubeQuality.Quality360P); Player.Source = Url.Uri; } catch (Exception) { } }
private async void PlayWithUpdateQuality() { var CurPosition = this.mediaPlayer.Position; var url = await YouTube.GetVideoUriAsync(VideoId, Settings.VideoQuality); if (url != null) { this.mediaPlayer.Source = url.Uri; this.mediaPlayer.StartupPosition = CurPosition; } }
public async void LoadState(string videoid) { if (videoid != "") { this.media.IsFullWindow = true; var url = await YouTube.GetVideoUriAsync(videoid, YouTubeQuality.Quality1080P); this.media.AutoPlay = true; this.media.Source = url.Uri; this.media.Play(); } }
/// <summary> /// Return all YouTube videeos /// </summary> /// <returns></returns> private async Task <List <YouTubeVideo> > GetYouTubeVideos() { List <YouTubeVideo> LstVideos = new List <YouTubeVideo>() { new YouTubeVideo { YouTubeId = "J--Zs64jMqw", Title = await YouTube.GetVideoTitleAsync("J--Zs64jMqw"), ThumbnailUri = YouTube.GetThumbnailUri("J--Zs64jMqw", YouTubeThumbnailSize.Large), VideoUri = await YouTube.GetVideoUriAsync("J--Zs64jMqw", YouTubeQuality.QualityHigh) }, new YouTubeVideo { YouTubeId = "razaRCeATaw", Title = await YouTube.GetVideoTitleAsync("razaRCeATaw"), ThumbnailUri = YouTube.GetThumbnailUri("razaRCeATaw", YouTubeThumbnailSize.Large), VideoUri = await YouTube.GetVideoUriAsync("razaRCeATaw", YouTubeQuality.QualityHigh) }, new YouTubeVideo { YouTubeId = "eHMUHwXG45s", Title = await YouTube.GetVideoTitleAsync("eHMUHwXG45s"), ThumbnailUri = YouTube.GetThumbnailUri("eHMUHwXG45s", YouTubeThumbnailSize.Large), VideoUri = await YouTube.GetVideoUriAsync("eHMUHwXG45s", YouTubeQuality.QualityHigh) }, new YouTubeVideo { YouTubeId = "JlnMYbHm3tU", Title = await YouTube.GetVideoTitleAsync("JlnMYbHm3tU"), ThumbnailUri = YouTube.GetThumbnailUri("JlnMYbHm3tU", YouTubeThumbnailSize.Large), VideoUri = await YouTube.GetVideoUriAsync("JlnMYbHm3tU", YouTubeQuality.QualityHigh) }, new YouTubeVideo { YouTubeId = "QacWskCibnU", Title = await YouTube.GetVideoTitleAsync("QacWskCibnU"), ThumbnailUri = YouTube.GetThumbnailUri("QacWskCibnU", YouTubeThumbnailSize.Large), VideoUri = await YouTube.GetVideoUriAsync("QacWskCibnU", YouTubeQuality.QualityHigh) }, new YouTubeVideo { YouTubeId = "QlAnthLUa5k", Title = await YouTube.GetVideoTitleAsync("QlAnthLUa5k"), ThumbnailUri = YouTube.GetThumbnailUri("QlAnthLUa5k", YouTubeThumbnailSize.Large), VideoUri = await YouTube.GetVideoUriAsync("QlAnthLUa5k", YouTubeQuality.Quality2160P) }, }; return(LstVideos); }
private async void loadVideo() { try { var url = await YouTube.GetVideoUriAsync("VYh9YDmCPoA", YouTubeQuality.Quality480P); mediaYoutube.Source = url.Uri; mediaYoutube.AutoPlay = false; } catch { } }
private async void OnPlayMovie(object sender, Windows.UI.Xaml.RoutedEventArgs e) { try { var url = await YouTube.GetVideoUriAsync("Gu6vmNz-PhE", YouTubeQuality.QualityLow); MediaElement.Source = url.Uri; MediaElement.Play(); } catch (Exception ex) { } }
protected override async void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); string videoId = String.Empty; Item = e.Parameter as Video; if (Item != null && !Item.Id.Equals(String.Empty)) { try { //Get The Video Uri and set it as a player source var url = await YouTube.GetVideoUriAsync(Item.Id, YouTubeQuality.Quality480P); player.Source = url.Uri; } catch (YouTubeUriNotFoundException _e) { Debug.WriteLine(_e.Message); MessageDialog message = new MessageDialog("This video is not availible, please select other"); await message.ShowAsync(); this.Frame.GoBack(); } } var backStack = Frame.BackStack; var backStackCount = backStack.Count; if (backStackCount > 0) { var masterPageEntry = backStack[backStackCount - 1]; backStack.RemoveAt(backStackCount - 1); // Doctor the navigation parameter for the master page so it // will show the correct item in the side-by-side view. var modifiedEntry = new PageStackEntry( masterPageEntry.SourcePageType, Item.Id, masterPageEntry.NavigationTransitionInfo ); backStack.Add(modifiedEntry); } // Register for hardware and software back request from the system SystemNavigationManager systemNavigationManager = SystemNavigationManager.GetForCurrentView(); systemNavigationManager.BackRequested += DetailPage_BackRequested; systemNavigationManager.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible; }