I imported a axWindowsMediaPlayer control to my form to play a sequence of pictures and/or small videos.
Now I want the user to adjust the slide show to his own needs, so he should be able to select the "showtime" of each picture and just play the video's length.
I tried to apply a timer to the form, and change the axWindowsMediaPlayer URL every "x" amount of seconds. This works perfectly for pictures, but videos now have an extra blank screen or footage cut off (depends on the time of the video compared to the "x" amount of seconds).
I want to to use an event, which will trigger when the media has stopped playing(so it wont cut off video's), but when I searched trough the axWindowsMediaPlayer event's list, I only found onMediaChanged. This event is kinda strange, it triggers a few times on the beginning of a video and at the end...
Is there anyway I can solve this? Maby using something different than the axWindowsMediaPlayer?
I found the solution after google'ing for hours. If anyone wants to know how to acces the axWindowsMediaPlayer's duration:
axWindowsMediaPlayer1.currentMedia.duration
It's a property (get and set) so this is all I needed.
Related
I'm making a Windows Form application that is supposed to play an animated gif while playing music.
I used SoundPlayer, and everything worked flawlessly. Then I found out I can't play multiple audio files with SoundPlayer, which was a problem (Background music AND effects needed).
So I looked a little bit into DirectSound, but my application froze everytime I did anything DirectSound related (Device, Buffer...).
So now I'm trying out WMP, I was happy at first, but when I enabled a GIF (Transparent, in case it matters), the music stopped in less than a second while you could see the GIF to stop for a frame or so, like it's loading something heavy. And this happens every time that audio and GIF are playing at the same time, no matter if one of them started in advance. When I used SoundPlayer, I could play 20 animated GIFs at once with no effect on audio.
To sum it up:
SoundPlayer = Only one audio file, unacceptable
DirectSound = Freezes for some reason (Maybe worth trying again? I'd like to put focus of this question on WMP though, I lost the code anyway)
WMP = Won't play along nicely with animated GIFs, which are required.
I tried playing both .wav and .mp3 file, no difference.
I added the wmp.dll reference before.
using System;
using System.Windows.Forms;
using System.Media;
private void button2_Click(object sender, EventArgs e)
{
var player = new WMPLib.WindowsMediaPlayer();
player.URL = "song.wav";
pictureBox1.Visible = true;
}
Is there something I should know about WMP? Can you recommend some other method? It does seem that the audio stops when the pocess reaches certain memory usage. It's steady on about 45 MB, but once I play the audio file it starts increasing, and plays until it reaches about 48 MB when it stops and returns to 45 MB.
Thanks for taking your time and helping me in any way.
EDIT: I was using a GIF picture with resolution of 500x500 which I used SizeMode=StretchImage on to actually make it appear smaller (200x200). In this case, the music played for about 0.2 seconds. I resized the resource picture to 100x100, using StretchImage to make it appear as 200x200 again, and the music played for about 8 seconds, about 4 seconds if I loaded two GIFs at once. Changing the .mp3 bitrate to make it just 170KB didn't help at all. I mean my Google Chrome takes 3GB of my memory and still plays multiple videos just fine, while my Form is taking not even 50MB and struggles. Surely there must be a way to play GIF and a song. Is there some kind of MemoryAssignLimit property? Or does WMP simply fail when it comes to bigger resources? Is it a limitation set by WinForms?
Followed this solution, and it worked like charm, GIFs everywhere and 30 overlapping songs, and nothing stops unless I want it to. Great.
Hello fellow developers.
I made a c# player to play videos and audio. To do that I used the System.Windows.Media MediaPlayer and it works great.
Here is the problem I encountered:
In some music files (not all of them) seeking to X time or playing it from the beginning to X time will have diffrent results.
In other words, If I play the song from the beginning, after 20 seconds the singer will say "Hello" but if I use the seek function to 20 sec I will hear the singer say something else (and 2 seconds later he will say "Hello").
I had to check if its the library mistake so I opened windows media player and played the song, When I click on the progress bar to X progress or when I play from the beginning to X progress the song is at different time.
Same like the library.
I checked this with VLC and it worked perfectly.
So here is my questions to you.
Does it mean that Media Player doesn't know how to seek this music file correctly?
Do you know how to fix this?
Should I use a different player, which one do you recommend?
I found the problem,
Encoding the audio as VBR made it happen like that.
Changing to CBR solved this.
I am creating a player using MediaUriElement. where i have a list of titles to play
which is a mix of both Image and Video. content will change in List Box selection change event.
i am using VisualBrush to replicate the video by filling to a rectangle in the same window for a mirror effect.
While running the application video and image plays good after some one hour there is a
delay in shifting from video to image. ie, if i select the next item in ListBox to play
then there is a delay like whole application hangs till the currently running video completes, then the selection change happens and the next title is playing in the player.
I don't know any particular reason for being like this.
Please help
I'm building a Windows Forms application in VS 2010 that smoothly increases or decreases the speed of a video playing back based on the speed of the user input.
I've tried several avenues..
1.) Using the AudioVideoPlayback DirectX class - I set the speed of the video, by setting the current position of the video, based on a timer.. and increased or decreased that value based on user input. While this worked on my PC, it lags a lot on our lower end target PC's. Can anyone think of a more efficient way to increase/decrease the speed of playback using this class?
2.) I've tried the Windows Media Player ActiveX control, and tried setting the rate/position dynamically, but this is extremely jumpy and laggy even on my development PC
3.) I've tried the Apple QuickTime Control 2.0 COM Component that comes with VS 2010, and it's also very laggy.
4.) I'm trying to figure out how to set the speed on the Shockwave Flash Object control, but haven't found that out yet
Can anyone suggest other avenues to explore? I just need to be able to increase/decrease the speed of video playback smoothly based on user input without lag. I don't care what format the video needs to be in, all videos can be converted to the required format.
Any help/ideas will be appreciated.
Thanks
The ultimate way is to decode the Bitmaps from videos, and handle the frames yourself.
Try the CaptureNET example from DirectShow.NET. It allows you to capture bitmaps from each frame. After that, write your own playback control to handle the refresh rate.
After trying many different formats/libraries and components I found the VLC Media Player ActiveX control to be the most efficient method to slow down/speed up video without any noticeable lag.
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)