Silverlight mediaelement: Automatically downloads are stopped after source is set.

Source: Internet
Author: User

Mediaelement is usually used to set the source and add it to the corresponding layout. mediaelement automatically connects to the remote streaming media and downloads it automatically. The following method can get only a part of the stream and then stop the download.

Dictionary <mediaelement, storyboard> mediaelementlist = new dictionary <mediaelement, storyboard> ();
Dictionary <storyboard, mediaelement> storyboadlist = new dictionary <storyboard, mediaelement> ();
Dictionary <storyboard, mediainfo> storyboadmediainfos = new dictionary <storyboard, mediainfo> ();

Public void loadmedias ()
{
List <mediainfo> mediainfolist = mediaaddresslist. getmediaitemlist ();
Foreach (mediainfo item in mediainfolist)
{
Mediaelement element = new mediaelement ();
Element. Source = new uri (item. source [0]);
Element. autoplay = false;
Element. bufferingtime = new timespan (0, 0, 0, 0,500 );
Element. mediaopened + = new routedeventhandler (element_mediaopened );
Storyboard = new storyboard ();
Storyboard. Duration = new duration (time span. fromseconds (0.5 ));
Storyboard. Completed + = new eventhandler (timer_completed );
Mediaelementlist. Add (element, storyboard );
Storyboadlist. Add (storyboard, element );
Storyboadmediainfos. Add (storyboard, item );
This. mediaelementpanel. Children. Add (element );
}
}

Private void removeelement (mediaelement)
{
This. mediaelementpanel. Children. Remove (mediaelement );
}

Private void element_mediaopened (Object sender, routedeventargs E)
{
Mediaelementlist [sender as mediaelement]. Begin ();
}

Private void timer_completed (Object sender, eventargs E)
{
Writeablebitmap bitmap = new writeablebitmap (storyboadlist [sender as storyboard] As mediaelement, new translatetransform ());
Mediaclipview clip = new mediaclipview ();
Mediainfo = storyboadmediainfos [sender as storyboard];
Image image = clip. mediaimage;
Image. width = 320;
Image. Height = 180;
Image. Margin = New thickness (5 );
Image. Source = bitmap;
Image. datacontext = mediainfo;
Clip. medialabel. Text = mediainfo. medialabel;
This. thumbnailspanel. Children. Add (CLIP );
Removeelement (storyboadlist [sender as storyboard]);
}

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.