Window Support

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Monday, 1 December 2008

Silverlight 2 : Playing Multiple Videos with One Media Element

Posted on 19:31 by Unknown

You may think that Playlist is always good option, though it is, sometimes it takes too much time to develop and test, so for small amount of video files, you can do play multiple videos by making use of Media_Ended() event.

I found many new things while doing demo of this, First surprise was that I was not able to declare “var” globally, I am researching on it why it had happened, Hashtable and ArrayList are seems to be not allowed in Silverlight though they are normal collections with .net framework, a surprise for me !

Code goes here :

public partial class Media : UserControl
    {


        int i = 1,j;
        Dictionary<int, string> temp = null;


        public Media()
        {
            InitializeComponent();

            temp = new Dictionary<int, string>();

            temp.Add(1, "http://localhost/Video1.wmv");
            temp.Add(2, "http://localhost/Video2.wmv");
            temp.Add(3, “http://localhost/Video3.wmv”);

            j = temp.Count;

            this.Loaded += new RoutedEventHandler(Media_Loaded);
            MasterMedia.MediaEnded += new RoutedEventHandler(MasterMedia_MediaEnded);
        }


        void MasterMedia_MediaEnded(object sender, RoutedEventArgs e)
        {
            if (i == j)
            {
                MasterMedia.Stop();
            }
            else
            {
                i++;
                MasterMedia.Source = new Uri(temp[i], UriKind.Absolute);            
            }
        }


        void Media_Loaded(object sender, RoutedEventArgs e)
        {
            if(i == 1)
              MasterMedia.Source = new Uri(temp[i], UriKind.Absolute);            
        }
}

As I told you that Hashtable and Arraylist was not in position so I have declare a “Dictionary” over here globally. I am adding URLs of media in it along with a key as integer so as to recognize what needs to be play. That can be track using global variables i and j.

This is the simplest way to play media in loop and you will observe the great usage of Media_Ended() event over here, how every time its getting fired. Do let me know your feedback on this if there are any more smart ways to do so.

Vikram.

Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • First Windows Phone 7 update February 2011 - Small update but Big start
    After tons of rumors and set of predictions on Windows Phone 7 all over Internet, Microsoft came up with first Windows Phone 7 minor update ...
  • The little Story of “I Unlock Joy” event by Microsoft and Pune User Group
      This post is about recent “I Unlock Joy” event happened in Pune which was conducted by Microsoft and Pune User Group. Little History : ...
  • Silverlight On Mobile : Windows Phone 7 Splash Screen and Customization
    After talking about 3D capabilities on Windows Phone 7 using Silverlight in last article , Now I am moving ahead with small but equally impo...
  • Silverlight 5 : Platform Invoke (PInvoke) in Silverlight
      Two days back Microsoft announced availability of Silverlight 5 RC,I encourage you to download bits from here , My friend Pete Brown alr...
  • Introduction to Speech Capabilities in Windows Phone 8 – Part 1
    After a long..I am writing blog, I hope and I wish I will resume blogging like I use to in past. Lots of things happened in past few months....
  • MCTS : Microsoft Silverlight 4 Development Exam Guide (70-506) by Packt Publishing
      Hello, After a long time I got chance to come back here.I will soon resume blogging in month of August. Last 4-5 months were horrible due...
  • Introduction to Speech Capabilities in Windows Phone 8 – Part 2
    Hope you enjoyed my last article on Speech Capability in Windows Phone 8, Today I am posting another part or you can say little extension t...
  • Silverlight 3 : Insert & Update Data using WCF Service with DataForm and DataGrid
    In my Lap around Silverlight 3 series, I have written a separate article on DataForm in Silverlight 3, This article is a basic extension to ...
  • Mango : Using DeviceStatus in Windows Phone 7.1
    First of all “Thank You” for your wonderful response and comments on my last article on Silverlight Vs HTML5 ,I hope you like the points I ...
  • Silverlight, HTML5 & Windows 8 : Where we are heading to ?
    This is not the post or yet another post on most happening debate of Silverlight and HTML5, This is just a visit to all of them to realize t...

Blog Archive

  • ►  2013 (4)
    • ►  August (1)
    • ►  April (3)
  • ►  2012 (4)
    • ►  July (1)
    • ►  March (2)
    • ►  January (1)
  • ►  2011 (24)
    • ►  December (1)
    • ►  September (4)
    • ►  August (2)
    • ►  July (1)
    • ►  June (4)
    • ►  May (3)
    • ►  April (3)
    • ►  March (1)
    • ►  February (4)
    • ►  January (1)
  • ►  2010 (21)
    • ►  December (1)
    • ►  November (2)
    • ►  October (3)
    • ►  September (2)
    • ►  August (4)
    • ►  July (5)
    • ►  May (1)
    • ►  April (1)
    • ►  March (1)
    • ►  January (1)
  • ►  2009 (49)
    • ►  December (1)
    • ►  November (5)
    • ►  October (2)
    • ►  September (1)
    • ►  August (5)
    • ►  July (5)
    • ►  June (1)
    • ►  May (5)
    • ►  April (5)
    • ►  March (9)
    • ►  February (4)
    • ►  January (6)
  • ▼  2008 (43)
    • ▼  December (3)
      • Integrating SQL Server Reporting Services with ASP...
      • IIS 7 : Reports and Database Manager features.
      • Silverlight 2 : Playing Multiple Videos with One M...
    • ►  November (9)
    • ►  October (7)
    • ►  September (4)
    • ►  August (2)
    • ►  July (3)
    • ►  June (4)
    • ►  May (3)
    • ►  March (3)
    • ►  February (5)
Powered by Blogger.

About Me

Unknown
View my complete profile