Alessandro Del Sole's Blog

/* A programming space about Microsoft® .NET® */
posts - 159, comments - 0, trackbacks - 0

My Links

News

Your host

This is me! This space is about Microsoft® .NET® and Microsoft® Visual Basic development. Enjoy! :-)

These postings are provided 'AS IS' for entertainment purposes only with absolutely no warranty expressed or implied and confer no rights.

Microsoft MVP

My MVP Profile

I'm a VB!

Watch my interview in Seattle

My new book on VB 2015!

Pre-order VB 2015 Unleashed Pre-order my new book "Visual Basic 2015 Unleashed". Click for more info!

My new book on LightSwitch!

Visual Studio LightSwitch Unleashed My book "Visual Studio LightSwitch Unleashed" is available. Click the cover!

Your visits

Follow me on Twitter!

CodePlex download Download my open-source projects from CodePlex!

Article Categories

Archives

Post Categories

.NET Framework

Blogroll

Help Authoring

Microsoft & MSDN

Setup & Deployment

Visual Basic 2005/2008/2010

Playing media contents in loop with the MediaElement control

The MediaElement control is used to play media contents in Technologies like WPF, Silverlight, WinRT and Windows Phone.

You might have the need to play a content forever, with a loop. A very easy way to accomplish this is Handling the MediaEnded and restart from there.

For example, we declare a boolean variable to store the loop state (enabled/disabled):

Private isLoop As Boolean = False

This can be useful if we associate the state of the loop to a button, which is just responsible to change its value:

    Private Sub LoopButton_Click(sender As Object, e As EventArgs)
        isLoop = Not isLoop
    End Sub

Somewhere else we'll start playing the content; the important thing is how we handle the event, like in the following example:

    Private Sub Media1_MediaEnded(sender As Object, e As RoutedEventArgsHandles Media1.MediaEnded
        If isLoop = True Then
            Me.Media1.Position = New TimeSpan(0)
            Me.Media1.Play()
        End If
    End Sub

Basically the code first checks if the loop state is active, then it moves the position back to zero and restarts playing.

Alessandro

Print | posted on giovedì 14 marzo 2013 11:04 | Filed Under [ Silverlight/Windows Phone Windows Presentation Foundation Windows 8 & WinRT ]

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 4 and 7 and type the answer here:

Powered by:
Powered By Subtext Powered By ASP.NET