This question is locked. New answers and comments are not allowed.
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
