Let's say I want to make a simple application that can play sounds. In WPF, I can use either the MediaPlayer class or the MediaElement class to take care of the playback.
Is it possible to actually extract data from the playing sound in order to draw the playing sound as a waveform (possibly using a charting library)? Something like in the image below. Alternatively, is it possible to at least obtain and display the output volume as we see in the Windows speakers system tray icon (second image below)?
Related
I need a very simple video player in my C# app. It only has to loop a video from file and nothing more. Since I'm developing a WPF application, I've tried to use System.Windows.Controls.MediaElement. It has all the functions I need, but works quite poor: I've played some full HD videos on it, and it's always lagging and spiking.
To make sure, it's not my app problem, I've created 2 test applications. The first in a WinForms borderless 1920x1080 window with only AxWMPLib.AxWindowsMediaPlayer control. And the second in a borderless WPF window of the same size with System.Windows.Controls.MediaElement.
Then I run 2 videos on both of players. Here are their specs:
1: 1920x1080, 12000kb/s, 25 FPS, wmv
2: 1920x1080, 5730kb/s, 25 FPS, mp4
On AxWindowsMediaPlayer everything looks fine. But MediaElement seems to drop some frames and ignore vertical sync (it's possible to see parts of one frame on another during fast scene changes). So, it's completely unsuitable and shouldn't be like that, but I've found nothing about the problem in Microsoft official docs (they only suggest to use MediaElement instead of AxWindowsMediaPlayer in WPF apps). Is it possible to make it work more smoothly or using an additional WinForms Form with AxWindowsMediaPlayer is the only solution?
It was written over five years ago (look up James Dailey messages in the thread), there were possibly some improvements but overall I suppose the statements are still in good standing. I will pick up some relevant quotes:
As you know the WPF environment is constructed from the ground up to offer developers a very rich “graphics first” environment. The MediaElement in particular was designed to allow you to mix video with various other UI components seamlessly. This solution will give you the flicker free, “draw over video” solution that you are looking for. The best part is you can do all of this in C#. The bad part of this solution is that the MediaElement is not designed for displaying time sensitive media content. In other words, the MediaElement is notorious for dropping and delaying the display of video frames. There are ways to minimize this such as using SD rather than HD content, use a video accelerated codec, etc.
also:
Unfortunately you can’t really tell the WPF MediaElement to never drop frames. The term we use for this class of issues is “disparate clocks”. In this case WPF is updating the screen at a certain rate (clock 1). The MediaElement (based on WMP) is cranking out video frames at a slightly different rate (clock 2). Given the underlying technologies there is currently no way to synchronize the two clocks and force them to “tick” at the same rate. Since the display will only be updated according to the WPF clock, multiple frames of video may be sent from the MediaElement to WPF between clock ticks. Because of this the MediaElement may appear to drop frames. This is a very common problem in multimedia development and there is no simple solution.
Windows Media Player uses Media Foundation and DirectShow APIs which power media playback with high quality video experience.
While beginnning audio playback, I need the ability to set the position in the audio file from where to begin the playback.
Please guide me with the API's to be used for this functionality.
Until now I have been using SoundEffectInstance for audio playback, but I do not see an option to set the audio playback position in that.
There are many different ways to play audio, see Media for Windows Phone. Without knowing which one you're using, it's a bit difficult to answer the question.
The MediaElement class has a settable property for Position that could serve your purpose.
I'm writing an application that is intended to embed audio or preferably video in a windows form.
Right now I am using the standard MediaPlayer class (xWMPLib.AxWindowsMediaPlayer MediaPlayer) and am finding that it may not have some of the functionality that I am hoping for.
One of the features I would like to have in this application is 'unadulterated scrubbing' of said audio or video... Which in this context I would define as 'the ability to scrub the video without stopping playback' - or otherwise, continuing to play audio or video While scrubbing...
Examples of this can be seen in programs such as Adobe Premier; in which you can scrub the position of your video on the timeline, and at whatever rate you are scrubbing, it will play back some 'garbled' audio.
The intention in this feature is to grant someone the ability to ( using a foot pedal, in one instance ) roll back in the media and know exactly where they are, based on audio feedback...
This particular feature is very specific and debatable in its ability to be achieved, but the core of the question here is this; What would be your suggestions for a 'more fully featured' media player that can be utilized in a C# windows form?
Thanks in advance.
I need to be able to play a "ding" sound in Windows 8 (a kind of beep that fades out gently), similar to what is seen here: http://tonematrix.audiotool.com/
Is it possible to somehow play this given a frequency? Or can I download sound files for this anywhere?
I noticed how the SoundPlayer no longer works, so the old code I used in my desktop program won't work anymore.
If you have a sound file of it, such as an mp3 or wav, use the MediaElement control. There are a few ways of doing this. For example, set the Source property to a URL (Uri class) or call SetSource() then the Play method.
Windows 8 does not include an easy way to generate a tone or pitch (assuming you mean metro/Windows Store apps). If you can generate the bytes needed to play the sound, place them in a buffer, create an IRandomAccessStream for it then pass it to SetSource. You can emulate the fade out by setting the Volume with a Timer.
It would be nice if there was a "fade out" audio effect that could be used with SetAudioEffect but Microsoft does not provide any audio effects at this time.
Is there a way to adjust the left/right balance when playing a sound in C# using the built in SoundPlayer class? I don't want to adjust the overall system balance, just the balance for the sound the program is playing.
Sound Player a simple lib to play wave files so dont think it has the capability. You can check the AXWindowsMediaPlayer for advance functionality
If you want to stick with SoundPlayer, you can create your Stream-derived class that will wrap around original wave file, but will manipulate sound samples and adjust left and right volume to your liking.