I was wondering if anyone can give me some insight on what is the prefered best option for playing a video in a Silverlight MediaElement. Right now I am using a direct link to a .wmv file on an mms server but the location is inconsistent and occasionaly locks up my ui when I try to load the video.
When this happens the storyboard animations that take place that is supposed present the video freeze up until the video is loaded then the animation catches up and jumps to the end. Looks really bad.
I have the option for smooth streaming as well. Just curious if there is a prefered best way to present video?
At a minimum you should not be starting your storyboards until the MediaOpened event has fired. And yes, smooth streaming would probably present the best user experience.
Related
I'm being annoyed by an odd behavior of Interop.quartztypelib in making media player with c#. With the help this link
http://www.codeproject.com/Articles/2632/DirectShow-MediaPlayer-in-C?msg=4853463#xx4853463xx
I created my own video player with Interop.quartztypelib. There's an important function for me to implement is that my application shall be able to capture the video image, just like you click "ALT" + "Printscreen" to make a screenshot of an active window in windows. But surprisingly I found that in the image captured by my application (I use
Graphics.CopyFromScreen
in my code), there's no video image on the video screen! I got the image of my form (the video player) but not the image of the video being played! And clicking "ALT" + "Printscreen" just gives me the same result!
I'm wondering if this Interop.quartztypelib doesn't support image capture. Anybody knows if there's a way to do settings to enable this? Thanks.
Printscreen doesn't do that
You need to implement some way of switching out of overlay, or some other way of getting a still. There is some trick with hardware acceleration, buts its not really applicable to you as the application dev. You're probably have to get antiquated with rendering api's.
For OpenGL api I think it would be glReadPixels.
For directX here's a SO question. I'm going to guess its directX in your case.
I have researched a lot on playing sounds for Windows Phone 8 devices and found multiple solutions but they don't quite match my case.
What I need : I'm writing an app (C#+XAML) that uses a file as background sound (must be active while navigating the whole app), and also to be able to play sound effects.
What are the issues :
For background sound I could use the BackgroundAudio Agent, but it doesn't meet my requirements because I want the sound to be played only in the background of my app, and to stop if my app closes or is not active.
For sound effects - I tried MediaElement which is okay, but I couldn't manage to make it somehow play while I am navigating the whole app. Media closes if I leave that page - I guess I could use this for the sound effects trick. Also, there's the SoundEffect which is not quite a good solution since it can play only .wav files... I could use it for sound effects only but not background sound (big sized files).
So, how should I proceed to play background sound (only inside my app) if I choose MediaElement/SoundEffect to play a sound effect in the app. I need a solution that would allow me to play 2 sounds at once (background and sound effect) and the background sound to be played only while the app runs (is active)...
So far I am confused and managed only to solve the sound effects issue.
Any suggestions are greatly appreciated.
The issue you are seeing with your MediaElement is that you are defining it to be part of the application page and it stops playing as soon as it disappears off of the Visual Tree (i.e. after OnNavigatedFrom).
If you define a MediaElement to be "visible" as part of the application frame, audio will keep playing while your app is active (you will need to handle deactivation events, naturally).
If you do this MediaElement should work for your "background audio".
Be aware you can only have one single active MediaElement playing media in your app, however you should be able to use SoundEffect for your sound effects.
Update:
To put your MediaElement in a frame, you will need to create a custom PhoneApplicationFrame class/XAML, add the MediaElement to that XAML, and refer to your custom frame in App.xaml.cs.
// Do not add any additional code to this method
private void InitializePhoneApplication()
{
if (phoneApplicationInitialized)
return;
// Create the frame but don't set it as RootVisual yet; this allows the splash
// screen to remain active until the application is ready to render.
RootFrame = new MyCustomPhoneApplicationFrame();
RootFrame.Navigated += CompleteInitializePhoneApplication;
See this Dzone article for more about Frame/Page in Windows Phone.
In practice, MediaElement is has some gotchas like the visual tree requirement. There are ways to get around it, but they are not optimal. I would suggest scrapping using MediaElement and use XAudio2 instead. It is native so default usage would be in c++, but you can also use SharpDX to access this framework from C#.
The advantage of XAudio2 is that you would not need to worry about sound dropping out when navigating around since it is not dependent on the UI. Another advantage is you could have one SourceVoice for handling your background audio, and other SourceVoices for handling sound effect playback. This all fits well within the model of usage the framework was designed for.
My goal here is to be able to play an MP3 in an OpenTK/OpenGL application (.NET but NOT windows forms), being able to stop/play/pause it, access/set the position of the audio file, and have it play to within a few milliseconds of when I tell it to.
I've tried using WindowsMediaPlayer (WMPLib) but for whatever reason the audio doesn't start playing until I resize or move the window. Not sure why but it probably has something to do with the fact that it's meant to be a control on Windows Forms, and this is a GL application.
I've tried using .NET's soundplayer but that incurs a huge delay of up to a second, and I can't set/access the position of the file.
I've looked into OpenTK and OpenAL but that seems way too complex to figure out.
Does anyone have any ideas?
THANKS!
Oh and worst case scenario I could also deal with playing WAV or OGG files instead, and if the play timing is accurate enough I wouldn't need access to the position of the audio.
OpenAL may seem complicated, but it sounds like the best solution to your problem. There's plenty out there on it, though most examples might be in other languages, but the API is the same. Perhaps this thread has some solutions as well.
I have a .NET Winform application and i need to show specific frames of a video file. Frames aren't necessarily in sequential order and are loaded when the user moves a slider, or when the application fires some events. I tried the following things:
Using EmguCV (OpenCV Wrapper): The problem here is that when i use SetCaptureProperty (With CAP_PROP.CV_CAP_PROP_POS_FRAMES, AVI_RATIO or MSEC ) to sets capture's position, the position isn't seted correctly (I checked it using GetCaptureProperty next to the SetCaptureProperty instruction). So, the frame returned by QueryFrame isn't the needed frame.
Using WPF MediaElement with Clock driven behavior: I can set the position of the video at the place that i need. The problem is that i don't know how get only one frame of the video sequence. By default, i have the Clock controller paused. When I set the position, If I call Clock.Controller.Resume(), then the video start playing from here. If I don't call Clock.Controller.Resume(), or if i call Clock.Controller.Resume() and then Clock.Controller.Pause() nothing is happening.
Im looking for another video library that can be used for accomplish this work, but i am not sure about what could be used. Any idea?
Thanks a lot for all comunity members, not only for help with this answer, but for the very big help that you give me with my problems every day. Iam new, but i would try to return these helping others with your problems.
Sorry for my terrible english! (Im spanish speaker and english speaking is not my best quality :S)
So I've been looking into the world of media playback for windows and I've started making a C# Media Player using DirectShow. I started off using the VRM-7 windowed video renderer and it was brilliant except it had a couple of small problems (multi monitors, fullscreen). But after some research I found that it's deprecated and I should be using VRM9.
So I changed it to use VRM9 windowless then found out that was an old post rofl >_< so finally I'm using Vista/Win7 (or XP .net 3) Enhanced Video Renderer (EVR) which is apparently the most up to date Microsoft video renderer and has all the flashy performance/quality things added to it. (tbh I haven't noticed any difference but maybe I need a blue-ray or HQ video to notice it).
With using EVR everything is working fine except resizing the video. Its really laggy/choppy/teary and probably something to do with its frame queueing mechanism.
To demonstrate my problem
open up windows media player classic.
View -> Options -> Playback -> output
Chose the "EVR" DirectShow Video renderer
Now restart wmp class and play a video, while it's playing click and drag a corner to resize it. You'll notice its horribly laggy. This is the exact same problem i am having.
But if you chose "EVR Custom Pres. **" or EVR Sync **" resizing works beautifully! So i tried googling around for anything about EVR resizing issues and how to fix it but i couldn't believe how little i could find. I'm guessing "Custom Pres." stands for "Custom Presenter" which sounds like they made their own.
Also you'll notice on the right hand size when you swap between EVR and the other EVR's the Resizer drop down on the right greys out.
So basically I wan't to know how I can fix this retarded resizing problem and is there any decent documentation out there? There is a fair bit for VMR7/9 but not much for EVR. I downloaded the DirectX SDK which apparently has samples but it was a waste of 500mb of bandwidth as it had nothing relevant.
Perhaps there is some way to force it not queueing up frames if that is the problem?
If you want code say the word and I'll paste some in. But it's really quite simple and nothing much happens, i'm convinced it's a problem with the EVR renderer.
EDIT: Oh and one other thing, what does VLC use? If you go into vlc options and change the renderer to anything but default, they all suck. So is it using VMR7? Or its own?
I need to write my own Custom Presenter, which from the looks of http://msdn.microsoft.com/en-us/library/bb530107(VS.85).aspx is a relatively big task.
Guess i'll look at the sample and try to go from there