Media Player Ended increment Cover flow selected index

2 posts, 0 answers
  1. Pawan Venugopal
    Pawan Venugopal avatar
    4 posts
    Member since:
    Dec 2009

    Posted 30 Dec 2009 Link to this post

    Hi ,

           I have a media player which plays when the coverflow is clicked. what i am trying to achieve is that once the video of the cover flow is ended i need to hide the video player increment the cover flow element by + 1 and start playing the next video corresponding to that cover flow element.  Can you show me a sample of how to achieve this.  this is the code which i used to increment the selected index of the cover flow element. But i am not sure how to play the video again.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using Telerik.Windows.Controls;

    namespace YoutubeViewer
    {
        public partial class VideoPlayer : UserControl
        {
            public bool IsSelected
            {
                get { return (bool)GetValue(IsSelectedProperty); }
                set { SetValue(IsSelectedProperty, value); }
            }

            public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(VideoPlayer), new PropertyMetadata(OnIsSelectedChange));

            private static void OnIsSelectedChange(DependencyObject d, DependencyPropertyChangedEventArgs args)
            {
                if ((bool)args.NewValue)
                {
                    (d as VideoPlayer).ShowMediaPlayer();
                }
                else
                {
                    (d as VideoPlayer).HideMediaPlayer();
                }
            }
            
            public VideoPlayer()
            {
                InitializeComponent();
                this.Loaded += new RoutedEventHandler(MediaPlay_Loaded);
                this.HideMediaPlayer();
            }

            void MediaPlay_Loaded(object sender, RoutedEventArgs e)
            {

                RadCoverFlowItem item = this.ParentOfType<RadCoverFlowItem>();
                this.SetBinding(IsSelectedProperty, new System.Windows.Data.Binding("IsSelected") { Source = item });

                this.HideMediaPlayer();
                

            }


            public void ShowMediaPlayer()
            {
               
                if (VisualStateManager.GoToState(this, "MediaPlayerState", true))
                {
                   //Info selectedItem = this.ParentOfType<MainPage>().coverFlow.SelectedItem as Info;

                    Info selectedItem = this.DataContext as Info;

                    if (this.MediaPlayerGrid != null && selectedItem != null)
                    {
                       RadMediaItem item = new RadMediaItem()
                        {
                           // Source = new Uri(selectedItem.LinkUrl,UriKind.RelativeOrAbsolute),
                            Source = new Uri("http://msstudios.vo.llnwd.net/o21/mix08/08_WMVs/T19.wmv", UriKind.RelativeOrAbsolute),
                            Title = selectedItem.Title,
                            ImageSource = new System.Windows.Media.Imaging.BitmapImage(new Uri(selectedItem.ThumbnailUrl,UriKind.RelativeOrAbsolute))
                        };
                                

                       this.MediaPlay.Items.Clear();
                       this.MediaPlay.Items.Add(item);

                        this.MediaPlay.Dispatcher.BeginInvoke(() =>
                            {
                                this.MediaPlay.CurrentItem = item;
                            });
                       
                    }
               }
            }

            public void HideMediaPlayer()
            {
                if (VisualStateManager.GoToState(this, "NormalState", true))
                {
                
                    if (this.MediaPlay != null)
                    {
                        this.MediaPlay.Stop();
                       
                    }
                }
            }

            private void MediaPlay_CurrentStateChanged(object sender, Telerik.Windows.RadRoutedEventArgs e)
            {
                if (this.MediaPlay.CurrentState == MediaElementState.Stopped)
                {
                    HideMediaPlayer();
                }
            }

            private void MediaPlay_MediaEnded(object sender, Telerik.Windows.RadRoutedEventArgs e)
            {
                HideMediaPlayer();
                int SelectedIndex = this.ParentOfType<MainPage>().coverFlow.SelectedIndex ;
                SelectedIndex++;


                //RadCoverFlowItem item = this.ParentOfType<RadCoverFlowItem>();
               // this.SetBinding(IsSelectedProperty, new System.Windows.Data.Binding("IsSelected") { Source = item });

                ShowMediaPlayer();  // show media player shows the same video. the selected index video does not get updated.
            }

            private void MediaPlay_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
            {
                if(!(e.OriginalSource is MediaElement))
                {
                    e.Handled = true;
                }

            }

            private void OnContentClicked(object sender, RoutedEventArgs e)
            {
               

                ShowMediaPlayer();
            }

            private void MediaPlayerGrid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
            {
                HideMediaPlayer();
            }


        }
    }

    Regards,
    Pawan Venugopal
  2. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 04 Jan 2010 Link to this post

    Hello Pawan,

    Unfortunately I was not able to reproduce the issue. Please find attached a sample project demonstrating this exact functionality. Have a look at it and let me know if I am doing anything wrong. Also, if you still experience the same problem, could you please attach a project reproducing the issue. This way I'll be better able to locate the origin of the problem.

    Kind regards,
    Kiril Stanoev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft banner
Back to Top