I'm working on a project right now where we are in need of seamless video transition between multiple videos in a WPF application.
A second monitor is being used as a media player, events are being sent to the screen to fire off videos, the video position is then being used to fire events back according to the video hitting specific intervals. The project is using a PRISM so the events are being fired by it's Event Aggregator.
The issue is finding a way of playing Videos in WPF that will accommodate for buffering between videos. I don't have code examples for methods tried but I have attempted to do this using.
The native WPF Media Element. This was very buggy and most certainly not user friendly. Bad play back and huge gaps between media files.
WPFMediaKit This is probably the best solution so far, video play back is fine with two issues. The media screen stops playing videos at it seems random times and the control goes black. And the transition between videos is about half a second of black.
Hosting AxWindowsMediaPlayer in a WindowsFormsHost. Play back is great but there is a huge gap between videos, even when running a playlist (This does not happen in Windows Media player so there could be something we are missing.) also as the control is hosted in a WindowsFormsHost I'm not sure if it is possible to keep(Bind) the videos position, and the position event does not appear to be caught.
GMF Play - Seems to have the same issues as WPFMediaKit except the seen is collapsed rather than the screen going black during transitions.
Edit
Media Player Example
Media Element Setup
private void CreateMediaKitElement()
{
WpfMediaKit.BeginInit();
WpfMediaKit.Stretch = Stretch.Fill;
WpfMediaKit.LoadedBehavior = WPFMediaKit.DirectShow.MediaPlayers.MediaState.Manual;
WpfMediaKit.MediaEnded += WpfMediaKit_MediaEnded;
WpfMediaKit.Volume = 0;
WpfMediaKit.EndInit();
}
private void PlayVideo(string uri, IEnumerable<Interval> intervals)
{
// Stop the current Audio track if a new video is being shown.
AudioElement.Stop();
WpfMediaKit.Stop();
// WpfMediaKit = null;
//Try recreating Element
WpfMediaKit = new MediaUriElement();
CreateMediaKitElement();
WpfMediaKit.Source = new Uri(uri, UriKind.Relative);
WpfMediaKit.Play();
}
So my question, does anyone know of or have an example of a method to play videos in WPF with a seamless transition between videos?
Thanks in advance,
Oli
Related
I'll start of by describing the problem, and then follow up with details about the process I'm going though.
Problem:
I'm having an issue where I'm playing a MediaElement on one storyboard and then setting the same MediaElement to hidden in another. After having the MediaElement set to hidden, I'm unable to replay the video portion of that storyboard again (non-MediaElement animations still happen.) Videos are WMVs encoded in VC-1 at 10,000 Kbps at a resolution of 1560x1004 and provided alongside the project as relative assets.
Details:
I'm working on a Kiosk application which makes use of a large number of videos combined with some graphical effects for real-time animation. Presently I'm creating storyboards using Blend, layering the videos for playback in the desired sequence. Below details two sample storyboard from the page:
Open performs the following:
Set's meOpen's visibility to 100%, Visible
Set's meIn's visibility to Hidden at 1 second (masking the start of meOpen)
Starts playing meOpen at 0:00.900.
Before playing the Close storyboard the Open storyboard is played, and the system waits for user input to continue. Once Close is triggered, the following happens:
meOpen - A MediaElement that has it's visibility set to 'Hidden' at 1 second
meClose - A MediaElement that is the desired video to play. I have it starting slightly before meOpen is hidden to mask the first frame 'black frame' while the element is loading the video
The rest of the items is just fading visibility of overlay elements.
The storyboard works for running through the video; however, if I try and play the Open storyboard a second time, meOpen does not play.
Thanks
Am new to Silverlight. Have added the MediaElement and Placed the Media file(.wmv format) with .xap file . ,Media Element is not visible . I want to know how can i Make it Visible on the application run...
Short answer is that a MediaElement is not a Media Player. At least no in the sense of all the UI goodness of buttons or dials, sliders and the like. For that you'll need to biuld, burrow or buy the player.
One place to start is with Microsoft Expression Encoder, that ships the complete source for a full featured, skinable player.
If you just need to play the media element without all of a media player functionalities (start, stop, next, pause and other buttons plus a progress bar), you can simply set it's property AutoPlay to true and it will start as soon as the page is loaded.
If you want some more control over the clip playback, you can call MediaElement instance methods like Play, Stop, Pause from your code behind.
I'm trying to make a text reader for my WP7.
I'm using a mediaElement in my reader.
at first every time the app read something, the MediaPlayer stopped, as I later discovered that is how it is designed.
Then I tried to try and trick the system, by using
mediaElement1.Stop();
mediaElement1.SetSource(isolatedStorageFileStream);
FrameworkDispatcher.Update();
MediaPlayer.Pause();
mediaElement1.Play();
if (mpState != MediaState.Stopped)
{ MediaPlayer.Resume(); }
now comes the wierd part,
when I use the reader once, it reads and the music seems to run without any pause, as I wanted, but when I use the reader for the second time, the MediaPlayer stops to play.
when I've added some breakpoints, I've noticed that after the first read, the MediaPlayer.state is paused, but it still plays.
I have some kind of a media player in my app, so I have some listBoxes that are filters, I want to read to selected filer (artist, album, etc.). so basically using the reader happens when selected item is changed. I'm using both MediaPlayer and MediaElement because if i won't pause the mediaPlayer, it will stop, and I will lose the position of the playing song. and because I want the reader to play gapless I'm using a mediaElement.
I'm lost...
Try looking at this (Music + Videos Hub Sample) http://go.microsoft.com/fwlink/?LinkID=203588 which I think you already use (using the media libraries on the phone), but try combining it with this (Silverlight Sound Sample) http://go.microsoft.com/fwlink/?LinkID=207868, which shows how to use XNA to play sounds in parallel.
If you carefully mix & match these 2 examples, you can achieve what you want, I’ve just tried it myself. Simply copied all that’s needed from example 1 into example 2, and it works just fine: the background music plays, and the birds happily chirp without harming one another.
Let me know if you have problems with it.
BTW - over here: http://msdn.microsoft.com/en-us/library/ff431744(v=vs.92).aspx you have many working examples, for many different things. I took both examples above from this link.
Eyal
I'm using VB.net 2010 and WPF 4. I need to have a smooth transition between two videos played on the mediaelement. I absolutely cannot use anything that requires me to use a winhost in the WPF window, as that will make my project impossible (since the video is full screen, and the controls are over the video)
Basically, I need for the video to play through, and then smoothly go to another video specified in code behind. I cannot splice the two videos together - they must be separate.
How do I have the videos transition smoothly, with no "blink"?
I'm guessing without testing here. You're probably going to need some CPU cores and a good video card.
If you have the memory, use two MediaElements.
Queue up both videos, one on each element.
Set the opacity of the second one to completely transparent. They're UIElements so this should work...
Use timers of some kind keyed from the start of playback on the first one so that you get an event a couple of seconds before playback ends.
With that event delegate, start the video in the second MediaElement, animate the first one's opacity to zero while simultaneously animating the second one to fully opaque.
If you need to do it again, set up the timer again and make sure your delegate animates things the other way.
I'm trying to be able to affect SpeedRatio on a MediaElement whilst having the media play in a continous loop.
This is possible through code behind; I can reset the position of the media once it has ended, but that creates a seam in the playback.
For seamless playback, I use a MediaTimeline, but when I use I media timeline, I can't change the SpeedRatio.
Has anyone got a different approach to looping playback in a mediaElement, or handling SpeedRatio?
UPDATE:
If I stop the timeline, change the timeline's SpeedRatio, I can produce the result I'm looking for. The only remaining problem is getting the timeline to start from the same position that it was stopped at. Pausing the timeline does not allow for the SpeedRatio to be changed.
I still welcome any alternatives.
My MediaUriElement in my open-source project has a "Loop" property that can provide seemless looping. Get it from the source because it's the newest.
The only solution I've found for this is to use XNA to control audio. It's got a lot more responsiveness.