Silverlight Custom control Multimedia video player

Source: Internet
Author: User
Tags silverlight

Silverlight itself provides a multimedia playback control, but does not encapsulate the controls that can be used directly. Search on the Internet some, are not very applicable, some too complex to refer to a large number of DLLs, feeling very bloated, some style does not fit. Silverlight provides only mediaelement, not as readily available as the previous HTML, so just wrap it up and do a simple player that satisfies the basic functionality. Learn about Blend's powerful change control style magic and implement a simple player through this essay.

Function points:

1, play, pause and display the current playback status

2, real-time display has played time

3, play the progress bar, and can drag the playback position

4, Full Screen button and double-click play screen into or out of full screen

5, adjust the volume

6. Play List

The basic function point of the player is the demand, the decomposition of requirements, the implementation of difficulties and functional points, assessment of workload and risk.

I. Understanding of MediaElement controls

Public mediaelementstate currentstate {get;}
The current state of the MediaElement. The state can be one of the following values (as defined in the Mediaelementstate enumeration):
buffering, Closed, Opening, paused, Playing, or Stopped.
The default value is Closed.

public bool AutoPlay {get; set;}
True if AutoPlay is, or false. The default value is true.
If this property is set to True before the Source property is set, the video is played automatically when the Source property is set.

Public Uri Source {get; set;}
Gets or sets the media source on the MediaElement. Specifies a Uniform Resource identifier (URI) string for a video.

Public double Volume {get; set;}
Gets or sets the volume size of the media.
 

//Occurs when the media stream has been validated and opened and the file header has been read. The total length of time that the video is obtained primarily from this event in the custom control.

 

Public event Routedeventhandler mediaopened

void mediaelement_mediaopened (object sender, RoutedEventArgs e)

{

This.playTools.TotaPlayTime = (int) This.mediaElement.NaturalDuration.TimeSpan.TotalSeconds;

}

//Occurs when the MediaElement no longer plays audio or video.

Sets the MediaElement to stop primarily through this event in the custom control, and determines whether to loop and resume playback.

Public event Routedeventhandler mediaended

void mediaelement_mediaended (object sender, RoutedEventArgs E

{

this.mediaElement.Stop ();

if (this. Isreplay)

{

This.mediaElement.Play ();

}

}

//Occurs when the value of the CurrentState property changes. The current video playback status information is displayed primarily through this event in the custom control.

Public event Routedeventhandler currentstatechanged

if this.mediaElement.CurrentState = = mediaelementstate.buffering)

{

This.playTools.CurrentMessage = this.mediaElement.CurrentState + '

+ math.round (this.mediaElement.BufferingProgress * 100, 0). ToString () + "%";/p>

}

//Occurs when an error is associated with the media Source. The MediaFailed event can occur under the following conditions:

1, File not found.

2, invalid (unrecognized or unsupported) media format.

3, unknown media error during playback.

//The error message is mainly displayed through this event in the custom control.

Public event EventHandler mediafailed

void mediaelement_mediafailed (object sender, Exceptionroutedeventargs e)

{

This.playTools.CurrentMessage = e.errorexception.message;

}

//This event occurs when playback is used to get the currently played time

Compositiontarget.rendering + + new EventHandler (compositiontarget_ Rendering);

Void Compositiontarget_rendering (object sender, EventArgs e)

{

int currenttime = (int) this.mediaElement.Position.TotalSeconds;

This.playTools.CurrentPlayTime = currenttime;

}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.