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]);
}