Please help to solve this problem It is Urgent

2 posts, 0 answers
  1. venu
    venu avatar
    6 posts
    Member since:
    Sep 2008

    Posted 06 May 2009 Link to this post

    hi,

       for the first time i am fetching 1 video playing it by making autoplay= true, then when mediaends the mediaended event
    is fired then it will fetch 15 videos and i am making isplaylistvisible= true and autoplay= false. now it will show playlist
    i,e 15 videos it's ok(the time slider will not move the video won't play in background), But the problem arises when i play it again i,e if i play 1 video among 15 videos by clicking  on it.
    the video plays, then mediaended event is fired and again 15 videos will be displayed in playlist  as usual it's ok this time the time slider will move i,e play list is visible but  a video is playing in the background this is the problem
     I want the mediaplayer and time slider  to be stopped when ever play list is visible.

     the code which  i am using is as follows.

    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;

     

    using

    System.Windows.Media.Imaging;

     

    using

    System.Windows.Browser;

     

    namespace

    PoptvMediaPlayer

     

    {

     

    public partial class SilverlightControl1 : UserControl

     

    {

    ServiceReference1.

    PoptvServiceClient client = new PoptvMediaPlayer.ServiceReference1.PoptvServiceClient();

     

     

    RadMediaPlayer radMediaPlayer1 = new RadMediaPlayer();

     

     

    public SilverlightControl1()

     

    {

    InitializeComponent();

     

    RadMediaPlayer radMediaPlayer1 = new RadMediaPlayer();

     

    radMediaPlayer1.EnableFullScreenIcon =

    true;

     

    radMediaPlayer1.HorizontalAlignment =

    HorizontalAlignment.Right;

     

     

     

    int videoId = Convert.ToInt32(GetCookie("poptvSL"));

     

    client.GetUserVideosCompleted +=

    new EventHandler<PoptvMediaPlayer.ServiceReference1.GetUserVideosCompletedEventArgs>(client_GetUserVideosCompleted);

     

    client.GetUserVideosAsync(videoId);

     

    //this.radMediaPlayer1.CurrentStateChanged += new EventHandler<Telerik.Windows.RadRoutedEventArgs>(radMediaPlayer1_CurrentStateChanged);

     

     

    this.radMediaPlayer1.MediaEnded += new EventHandler<Telerik.Windows.RadRoutedEventArgs>(radMediaPlayer1_MediaEnded);

     

    }

     

    void radMediaPlayer1_MediaEnded(object sender, Telerik.Windows.RadRoutedEventArgs e)

     

    {

     

     

    this.radMediaPlayer1.Stop();

     

     

    //radMediaPlayer1.AutoPlay = false;

     

     

    this.LayoutRoot.Children.Remove(radMediaPlayer1);

     

    client.Get15UserVideosCompleted +=

    new EventHandler<PoptvMediaPlayer.ServiceReference1.Get15UserVideosCompletedEventArgs>(client_Get15UserVideosCompleted);

     

    client.Get15UserVideosAsync();

     

    //MediaElementState state = radMediaPlayer1.CurrentState;

     

     

    //state = MediaElementState.Closed;

     

     

     

     

     

    }

     

    void client_Get15UserVideosCompleted(object sender, PoptvMediaPlayer.ServiceReference1.Get15UserVideosCompletedEventArgs e)

     

    {

     

     

    this.LayoutRoot.Children.Remove(radMediaPlayer1);

     

     

     

    radMediaPlayer1.IsPlaylistVisible =

    true;

     

    radMediaPlayer1.Width = 1117;

    radMediaPlayer1.Height = 420;

     

    this.radMediaPlayer1.AutoPlay = false;

     

    System.Collections.ObjectModel.

    ObservableCollection<PoptvMediaPlayer.ServiceReference1.UserVideo> str1 = e.Result;

     

     

    List<RadMediaItem> radMediaItem = new List<RadMediaItem>();

     

     

    foreach (var i in str1)

     

    {

     

    RadMediaItem mediaItem = new RadMediaItem

     

    {

    Source =

    new Uri(i.VideoURL, UriKind.RelativeOrAbsolute),

     

    ImageSource =

    new BitmapImage(new Uri(i.Snapshot, UriKind.RelativeOrAbsolute)),

     

    Title = i.SongName

    };

    radMediaItem.Add(mediaItem);

    }

     

    foreach (RadMediaItem i in radMediaItem)

     

    {

    radMediaPlayer1.Items.Add(i);

    }

     

    this.LayoutRoot.Children.Add(radMediaPlayer1);

     

     

     

    }

     

    void client_GetUserVideosCompleted(object sender, PoptvMediaPlayer.ServiceReference1.GetUserVideosCompletedEventArgs e)

     

    {

     

    radMediaPlayer1.Width = 1117;

    radMediaPlayer1.Height = 420;

    radMediaPlayer1.AutoPlay =

    false;

     

     

    //radMediaPlayer1.AutoPlay = true;

     

    System.Collections.ObjectModel.

    ObservableCollection<PoptvMediaPlayer.ServiceReference1.UserVideo> str1 = e.Result;

     

     

    List<RadMediaItem> radMediaItem = new List<RadMediaItem>();

     

     

    foreach (var i in str1)

     

    {

     

    RadMediaItem mediaItem = new RadMediaItem

     

    {

    Source =

    new Uri(i.VideoURL, UriKind.RelativeOrAbsolute),

     

    ImageSource =

    new BitmapImage(new Uri(i.Snapshot, UriKind.RelativeOrAbsolute)),

     

    Title = i.SongName

    };

    radMediaItem.Add(mediaItem);

    }

     

    foreach (RadMediaItem i in radMediaItem)

     

    {

    radMediaPlayer1.Items.Add(i);

     

    }

     

     

     

    this.LayoutRoot.Children.Add(radMediaPlayer1);

     

     

    }

     

    public override string ToString()

     

    {

     

    return Name;

     

    }

     

    private string GetCookie(string key)

     

    {

     

    string[] cookies = HtmlPage.Document.Cookies.Split(';');

     

     

    foreach (string cookie in cookies)

     

    {

     

    string[] keyValue = cookie.Split('=');

     

     

    if (keyValue.Length == 3)

     

    {

     

    if (keyValue[1] == key)

     

     

    return keyValue[2];

     

    }

    }

     

    return null;

     

    }

     

    //private void radMediaPlayer1_CurrentStateChanged(object sender, Telerik.Windows.RadRoutedEventArgs e)

     

     

    //{

     

     

     

    //}

     

     

    }

    }

    please suggest me as soon as possible.

    regards
    Venugopal

  2. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 06 May 2009 Link to this post

    Hi Venu,

    Can you make sure that you unregister from the events when they have finished and are not needed anymore like so:

    radMediaPlayer1.MediaEnded -= radMediaPlayer1_MediaEnded;

    Also could you try explicitly stopping the MediaPlayer:

    radMediaPlayer1.Stop();

    Regards,
    Miroslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft banner
Back to Top