locked
How to redirect to YouTube page if the video is not opening from the app

    Question

  • I am developing a Windows 8 app for Music Artists. Basically I take the YouTube feed and display the videos for that particular artist. I am using the following code to display the video,

    string videoId = youtubeId;
    var url = await YouTube.GetVideoUriAsync(videoId, YouTubeQuality.Quality1080P);
    YouTubeVideoDisplay.Source = url.Uri;

    However some videos are not opening directly from the app. So for those videos I am opening the YouTube page.

    Now for the videos, which are not opening directly from the app, I want to redirect to the YouTube page after waiting for 30 sec and I am using the DispatcherTimer to count 30 sec. Please check the complete code as below,

    private DispatcherTimer _timer;
    private int _countdown;
    
    protected override void OnNavigatedTo(NavigationEventArgs e)
    { 
      _countdown = 1;
      _timer = new DispatcherTimer();
      _timer.Interval = TimeSpan.FromSeconds(30);
      DisplayYoutubeVideo(youtubeId);//Method to open the video directly
      _timer.Tick += (s, c) => Tick();
      _timer.Start();
    }
    
    private void Tick()
    {
      _countdown--;
      if (_countdown == 0)
      {
         _timer.Stop();
         _timer = null;
      }
      OpenVideoInYT();//Method that opens the YouTube Page
    }

    However this code is always redirecting the app to the YouTube page. So I want to put a condition that if the direct video is working fine then the app will not redirect to the YouTube page.

    Also I want to stop the timer when the back button got pressed but _timer.stop() is not working for that.

    Please let me know what change I have to make.

    Saswati

    Saswati Sanyal Blog : http://saswatisanyal.blogspot.com/


    • Edited by Saswas Wednesday, February 26, 2014 9:28 AM
    Wednesday, February 26, 2014 9:27 AM

Answers

  • Hi Saswas,

    I cannot help with the internals of MyToolkit. You'll need to ask the authors how to determine what the video is doing.

    --Rob

    Tuesday, March 04, 2014 12:23 AM
    Owner

All replies

  • What part of this do you need help with? What isn't working the way you want, and in what way isn't it working?

    What is the YouTube object you list? How does it report failure if it cannot show the video?

    --Rob

    Wednesday, February 26, 2014 4:11 PM
    Owner
  • I am basically taking the YouTube Video id and opening that video with the help of Mytoolkit (GetVideoUriAsync()). So I want to add a check point whether the video is opening or not. If the video is not opening then after 30 sec the app will open that particular video in YouTube by using the IE.

    Now I need a help to add that check point which will let me know whether the video has opened or not.   

    Another issue is, I am calculating the 30 sec by using DispatcherTimer. Now I want to stop the timer when the back button is clicked. But the stop() is not working.

    Thanks

    Saswati


    Saswati Sanyal Blog : http://saswatisanyal.blogspot.com/

    Thursday, February 27, 2014 4:39 AM
  • Hello Rob,

    Please let me know if you need any further information from me regarding this.

    Thanks

    Saswati


    Saswati Sanyal Blog : http://saswatisanyal.blogspot.com/

    Sunday, March 02, 2014 11:15 AM
  • Hi Saswas,

    I cannot help with the internals of MyToolkit. You'll need to ask the authors how to determine what the video is doing.

    --Rob

    Tuesday, March 04, 2014 12:23 AM
    Owner