How to Play youtube videos in windows phone 7?

2020-07-30 00:56发布

问题:

I am Beginner in Windows phone 7. and here my question is that "How can we play the video from page url directly in our application in windows phone 7 ??"

For example, the page url = http://www.youtube.com/watch?v=EhfuBLe7sio

and i want to play that video in my application with MediaPlayerLauncher or MediaElement

Please, Give me Answer.. m waiting..

回答1:

And finally, I solved my question with the help of Toolkit.codeplex.

and i played the youtube video directly in my windows phone application using this code.

    public delegate void mymethod(YouTube.YouTubeUri myuri, Exception myexec);

    mymethod mm;

    private void BtnGetVideo_Click(object sender, RoutedEventArgs e)
    {
        SystemTray.ProgressIndicator.IsVisible = true;
        var url = YouTube.GetVideoUri("CT3dsZhCjsk", YouTubeQuality.Quality1080P, myCompleted);
    }

    public void myCompleted(YouTube.YouTubeUri uri, Exception e)
    {
        Dispatcher.BeginInvoke(new mymethod(nikdemo), uri, e);
        // i used Dispatcher.BeginInvoke. and invoked my delegate until it will gives the error like Invalid cross-thread Operation.

    }

    public void nikdemo(YouTube.YouTubeUri uu, Exception ee)
    {
        //MyMedia.Source = uu.Uri;

        string retr = uu.Uri.ToString();
        MyMedia.Source = new Uri(retr,UriKind.Absolute);
        MyMedia.Play();
        MyMedia.AutoPlay=true;
        SystemTray.ProgressIndicator.IsVisible = false;
    }

And finally i seen that you tube video in my application on windows phone.