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.
Related
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
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
i want to play an audio or video file, and i made this but i do not know how i can check whether media element is playing file or not?
Like using same button for Pause and Play how i can know that media is also playing file or not?
i use below code to play the file
mediaElement1.LoadedBehavior = MediaState.Manual;
mediaElement1.Source = new Uri("C:/test.wma", UriKind.RelativeOrAbsolute);
mediaElement1.Play();
And one more thing i know how to play file in media element by code. I want to to design media element UI. how i can design this for both video and audio files? what properties should enable and what should be disable.
Last I checked you can't unless you are using Silverlight:
http://msdn.microsoft.com/en-us/library/cc189079(v=vs.95).aspx
I have an application using .Net 4 and as far I can remember you cannot verify if it is playing, stopped, paused, etc.
This is what you can do with .Net 4:
http://msdn.microsoft.com/en-us/library/system.windows.controls.mediaelement(v=vs.100).aspx
Compared with Silverlight:
http://msdn.microsoft.com/en-us/library/system.windows.controls.mediaelement(v=vs.95).aspx
I have a video with transparent background in .avi format (Made from Adobe After Effects), but the transparent background appears black in mediaelement. Media Player has no background property also.
What should i use so that this media element plays the file and when placed on an image takes that image as its background. (No i cannot embed that image in the avi file as my image keeps changing).
*If my approach is wrong please let me know.
I'm afraid using the normal wpf media player this can't be done.
The mediaplayer ignores the transparent regions, even with video formats that accept it. From memory, i dont think AVI files support transparent regions. MOV files do.
Having said that, and although it could be a very complicated task, it may be possible to enhance the WPFMediaKit mediaplayer to do what you want.
http://wpfmediakit.codeplex.com/
J Morrill the author of wpfmediakit may be able to let you know if it is possible or not.
I might add that i got around this problem in a project once by using a sequence of .png files that played a short 10 second movie. Of course this is not an ideal solution, but it got me out of a jam
Another workaround is to use color keying - assing a color (or more colors) in your video, which you translate to the transparency by a WPF Effect(BitmapEffect or ShaderEffect).
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.