How to Play a Video from YouTube

4 posts, 0 answers
  1. Vuyiswa Maseko
    Vuyiswa Maseko avatar
    187 posts
    Member since:
    Jan 2010

    Posted 11 Nov 2011 Link to this post

    Good Day All I want to play a video in YouTube using the Mediaplayer. My Xaml looks like this 

         <telerik:RadMediaPlayer Height="446"  HorizontalAlignment="Left" Name="SermonsPlayer" IsAutoPlaylistAdvance="True" IsAutoReverse="True"
    SelectedIndex="0" IsPlaylistVisible="True" VerticalAlignment="Top" Width="813" Grid.Row="1" >
              <telerik:RadMediaPlayer.ItemTemplate>
                  <DataTemplate>
                      <telerik:ContainerBinding.ContainerBindings>
                          <telerik:ContainerBindingCollection>
                              <telerik:ContainerBinding Binding="{Binding Source}" PropertyName="Source" />
                              <telerik:ContainerBinding PropertyName="ItemsSource"
                                      Binding="{Binding Source}" />
     
                          </telerik:ContainerBindingCollection>
                      </telerik:ContainerBinding.ContainerBindings>
                      <StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
                            <TextBlock Margin="4"
                             VerticalAlignment="Center"
                             Text="{Binding Title}" />
                      </StackPanel>
                  </DataTemplate>
              </telerik:RadMediaPlayer.ItemTemplate>
     
          </telerik:RadMediaPlayer>

    and my class and the way i get data looks like this 
    public partial class VideoSermons : ChildWindow
       {
           public VideoSermons()
           {
               InitializeComponent();
               SermonsPlayer.ItemsSource = GetItems();
           }
     
           public static ObservableCollection<MediaItem> GetItems()
           {
               MediaItem item1 = new MediaItem
               {
                   Source = "http://www.youtube.com/watch?v=DYwIRy3_BVA",
                   Title = "Creflo Dollar - The Truth About Hell 1 of 3"
               };
               MediaItem item2 = new MediaItem
               {
                   Source = "http://www.youtube.com/watch?v=Tx8EhtxZrls",
           
                   Title = "Pastor Creflo Dollar - The Truth About Hell"
               };
               MediaItem item3 = new MediaItem
               {
                   Source = "http://www.youtube.com/watch?v=Z7zaj_S_6Dc",
        
                   Title = "Joel Osteen - Overcoming Anger"
               };
                 
     
               MediaItem item4 = new MediaItem
               {
                   Source = "http://www.youtube.com/watch?v=YVc-JsTmOHY&feature=related",
                
                   Title = "Creflo Dollar speaks about marriages (perfect mates)"
               };
                 
     
     
                   MediaItem item5 = new MediaItem
               {
                   Source = "http://www.youtube.com/watch?v=sG2bh0HyeBE&feature=related",
                 
                   Title = "Creflo Dollar-How to Avoid Fornication"
               };
     
     
                
                   MediaItem item6 = new MediaItem
               {
                   Source = "http://www.youtube.com/watch?v=4Zb3CSnemTg&feature=related",
               
                   Title = "TD Jakes - Relationships"
               };
     
     
     
     
                 
                      
                   MediaItem item7 = new MediaItem
               {
                   Source = "http://www.youtube.com/watch?v=rZpcRemufO4",
                  
                   Title = "T.D. Jakes 5 People In Your Life"
               };
                 
                            
                   MediaItem item8 = new MediaItem
               {
                   Source = "http://www.youtube.com/watch?v=WIRSYBMeW-0&feature=related",
                   
                   Title = "Joel Osteen - Having Mountain Moving Faith"
               };
                 
     
     
               MediaItem item9 = new MediaItem
               {
                   Source = "http://www.youtube.com/watch?v=tKE0WkbXPC0&feature=relmfu",
              
                   Title = "Remind God What He Said"
               };
                 
     
     
               MediaItem item10 = new MediaItem
               {
                   Source = "http://www.youtube.com/watch?v=5VNVI2tK7Zw&feature=related",
                 
                   Title = "Joel Osteen - Say 'NO' To Your Feelings"
               };
                 
     
     
               MediaItem item11 = new MediaItem
               {
                   Source = "http://www.youtube.com/watch?v=XskzFKpALrg",
                  
                   Title = "Resisting Temptation"
                    
               };
                 
               MediaItem item12 = new MediaItem
               {
                   Source = "http://www.youtube.com/watch?v=aU5kek3D-4I",
                   
                   Title = "Joel Osteen teaches Christians about PORK!"
               };
               ObservableCollection<MediaItem> items = new ObservableCollection<MediaItem>();
               items.Add(item1);
               items.Add(item2);
               items.Add(item3);
               items.Add(item4);
               items.Add(item5);
               items.Add(item6);
               items.Add(item7);
               items.Add(item8);
               items.Add(item9);
               items.Add(item10);
               items.Add(item11);
               items.Add(item12);
               return items;
           }
     
           public class MediaItem
           {
               public string Image { get; set; }
               public string Source { get; set; }
               public string Title { get; set; }
               public bool IsStreamingSource { get; set; }
           }
     
          
       }

    now i can load the Videos in a Playlist , but when clicking the Playlist the Video does not play , i get the Error 

    Failed to Open Media!

    Thanks 


  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 16 Nov 2011 Link to this post

    Hello Vuyiswa Maseko,

     The RadMediaPlayer wraps a collection of the Silverlight MediaElements. Unfortunately, you cannot use MediaElement to play youtube videos directly. You need to user source link point directly to the media file.
    You can check out this stackoverflow post for more info.

    All the best,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Chon
    Chon avatar
    5 posts
    Member since:
    Nov 2008

    Posted 20 Jan 2015 in reply to Petar Mladenov Link to this post

    Since this post is 3 years old now, I was wondering:

    Is it still not possible to play a youtube video directly from the mediaplayer element? 

    If it is possible, could you please provide me with some sample xaml demonstrating how to play a youtube video?

    Thanks!
    Chon
  5. Kiril Vandov
    Admin
    Kiril Vandov avatar
    324 posts

    Posted 22 Jan 2015 Link to this post

    Hello Chon,

    YouTube uses FLV format for streaming the video, which is proprietary format and is unplayable by native Silverlight applications. This is a framework limitation and that is why the RadMediaPlayer is not able to play such videos. The RadMediaPlayer uses MedialElement internally and it could play almost everything that runs successfully in MediaElement.

    I hope this information helps.

    Kind regards,
    Kiril Vandov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top