Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Switching Source of MediaElement at Runtime (Silverlight 2.0)
9 replies. Latest Post by quilnux on July 21, 2009.
(0)
quilnux
Member
26 points
44 Posts
03-13-2009 4:13 PM |
I have a project which I am trying to play 3 WMV videos, each video is 5 minutes long.
I can play the first video just fine but when it's finished I use the MediaEnded event handler to switch the source for the second video.
Uri VideoUri = new Uri("http://localhost/Videos/Video-2.wmv");
MediaElement.Source = VideoUri;
But when I do that the connection closes. If I load a video that is 10 seconds or less and after playing that, try to load the second video it works. It just won't if the video is longer then 10 seconds.
I think it may be due to the browser connection being closed by KeepAlive after 15 seconds of idle.
Is there a way to reopen the browser connection in Silverlight or is there another way to do what I am wanting?
Thanks.
fullsail...
Contributor
3699 points
829 Posts
03-13-2009 7:30 PM |
Hi! Are you setting this new video like this? myPlayer.Stop(); myPlayer.Source = new Uri("http://localhost/Videos/GirlsGoneWild4.wmv", UriKind.Absolute); myPlayer.Position = TimeSpan.FromSeconds(0); myPlayer.Play();
03-13-2009 7:44 PM |
Basically, We don't set the position to zero though, You have:
myPlayer.Position = TimeSpan.FromSeconds(0);
I was assuming that it resets the position to 0 when you switch the source. Do I assume wrong?
Thanks,
03-13-2009 7:50 PM |
Oh, I have no idea. lol I've just always set it. Do you still have the problem?
struggle...
578 points
102 Posts
03-13-2009 7:52 PM |
...Ahhh when you re-set the source, mediaelement will reload all data...
If you want to "Continue" your position, you may face to the streaming problem, that is, your media data will be streamed from 0, you want to watch it at "70" which is just the previous media's "current position".
I think a better way to solve this is create 3 mediaelment (which is 3 parts of your "whole" clip), and you have to add them to your visual-tree otherwise they won't load!
And you've to set 2 Mediaelement's postion to your target position or just let them buffering, and also Opacity = 0, not visiblity... And volume = 0;
Ok when your 1st media is "at the point", you can dispose it and let "2nd" shows up....
Interesting condition uh?
good luck~
03-13-2009 7:59 PM |
struggle-luan: ...Ahhh when you re-set the source, mediaelement will reload all data... If you want to "Continue" your position, you may face to the streaming problem, that is, your media data will be streamed from 0, you want to watch it at "70" which is just the previous media's "current position". I think a better way to solve this is create 3 mediaelment (which is 3 parts of your "whole" clip), and you have to add them to your visual-tree otherwise they won't load! And you've to set 2 Mediaelement's postion to your target position or just let them buffering, and also Opacity = 0, not visiblity... And volume = 0; Ok when your 1st media is "at the point", you can dispose it and let "2nd" shows up.... Interesting condition uh? good luck~
We wanted to do that but we found out that the 3 clips are hosted on 3 different servers and we are not able to put them together. This was our original design plan.
03-13-2009 8:01 PM |
fullsailrick:Oh, I have no idea. lol I've just always set it. Do you still have the problem?
Checking now. I just added the TimeSpan and initial testing was promising but I'm trying against the published video files so I will know in about 3 minutes 12 seconds so I'll let you know.
03-13-2009 8:27 PM |
heh, wow.. Adding the TimeSpan.FromSeconds(0); fixed it.
Thanks for the help! It's very interesting.
YoungOZ
16 points
4 Posts
07-21-2009 10:11 AM |
Can you please post the codes that you are currently using to play the Video. I'm trying to accomplish the same task.
Thanks
07-21-2009 1:23 PM |
YoungOZ: Can you please post the codes that you are currently using to play the Video. I'm trying to accomplish the same task. Thanks
{
VideoPlayer.Source = VideoUri;
VideoIndex = 1;
}
VideoIndex = 2;
VideoIndex = 0;
VideoIndex is a variable that is used to determine which video is being played. I assign each video an index and use that index to track which is playing so I know what is next in the playlist. You will want to add some boolean or something for your stop button if you have one because the stop button still cause this code to execute under MediaEnded. I just put all this code around an if conditional and had the stop button change a boolean to true. if the boolean is true, the stop button was pressed, don't execute this code. If it's false and the media ended (got to the end of the video itself) then move to the next video. If the last video was played, reset the video to the first one and reset the VideoIndex to 0.