Click here to Skip to main content
Click here to Skip to main content

Silverlight Media Player

By , 6 Apr 2009
 

Introduction

You must have come across a couple of Silverlight media players on the internet. Here are some cool features that I have given in mine:

  • Full screen mode
  • Vertical sliding menu in normal mode
  • Horizontal sliding menu in full screen mode
  • Standard control panel
  • Drag n Drop play from menu in normal mode

Moreover, I have used basic Silverlight features like animation using storyboards, Silverlight user controls, media element, control transforms, gradient brushes and LINQ for data access. So it's a good example for Silverlight beginners to start with.

NOTE: I have not included the video files with the demo application attached with the article because of large file sizes. But you can use any Silverlight compatible media format files that are given on the MSDN site:

Supported Media Formats, Protocols, and Log Fields

In case a media file does not have a compatible file format, you would get a JavaScript error in the explorer status bar saying:

Sys.InvalidOperationException: MediaError error #3001 in control 'Xaml':AG_E_INVALID_FILE_FORMAT (do not start pulling your hair, try different files :))

You can add your video files in the ClientBin folder of the web application MediaPlayerLive in the attached demo application.

And for this demo to work, you would need to have Silverlight 2.0 and Windows media player 10 or above installed your machine.

Another common error related to mediaelement control is:

Sys.InvalidOperationException: MediaError error #4001 in control 'Xaml':AG_E_NETWORK_ERROR

This simply means the control cannot find the source specified.

MediaPlayer2.jpg

Inside Look

I have used a simple data.xml file for storing the list of video files.

<videos>
  <video id="0" vid="demo.wmv" img="v1.jpg" >
  <video id="1" vid="demo2.wmv" img="v2.jpg" >
  .
  .
<videos >

The class DataAccess.cs does the fetching operation of data from this file. LINQ queries are used to show specific paged data in the sliding menu.

XDocument xDoc = XDocument.Load("Data.xml");
          var xVids = from v in xDoc.Descendants("Video") where 
          v.Attribute("img").Value.Length>0 && v.Attribute("vid").Value.Length>0
          select new
          {
              img = v.Attribute("img").Value,
              vid = v.Attribute("vid").Value,
              id = v.Attribute("id").Value
          };

I have seen quite a few sliding image gallery controls on the internet, but all were JavaScript based. I've never been a fan of JavaScript myself, so I thought I would write my own user control for those C# lovers. I hope you find it useful considering that I have given an idea of how to make it parameterized for different sizes and count of images shown. I always try to keep some things incomplete in my article for the readers to try out themselves.

This example should be a good sandbox to build your custom features around this standard media player. I would also be posting updates to this player soon.

History

  • 4th April, 2009: Initial version

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication

About the Author

sunit_82
Software Developer (Senior) Geometric
India India
Member
B.E. in Information Technology
MCTS(.NET 2.0 )

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 3memberbernadali29 Dec '10 - 7:01 
QuestionProject not opening in Visual Studio 2008memberAmulkumar Pandya14 Oct '10 - 2:05 
QuestionWhy we need Windows media player 10 or above installed on machine for this?memberTeroBau1 Mar '10 - 5:19 
AnswerRe: Why we need Windows media player 10 or above installed on machine for this?memberMember 16562146 Apr '10 - 5:11 
GeneralThe question about slidermembersea_caty21 Sep '09 - 16:42 
QuestionDataAccess.cs to adapt the class to receive data from a DatabasememberLuizItatiba3 Jun '09 - 8:56 
Hello I would like to know how I could adapt the fields: img, vid and id in the same class DataAccess.cs to be recovered based on a select from a database SQL or MYSQL there any example or as I would have to adapt the class to import data from a database
 
I look at now and I thank
 
Translated from Portuguese into English by Google Translator
 
LADEF

QuestionCan we use serverside playlist inside stackpanel?memberAboShehab_FCIS26 May '09 - 0:54 
AnswerRe: Can we use serverside playlist inside stackpanel?membersunit_8226 May '09 - 1:37 
GeneralRe: Can we use serverside playlist inside stackpanel?memberAboShehab_FCIS26 May '09 - 4:35 
GeneralRe: Can we use serverside playlist inside stackpanel?membersunit_8227 May '09 - 3:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 6 Apr 2009
Article Copyright 2009 by sunit_82
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid