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.
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.
I am writing a wave audio player using C# and winmm.dll. To reduce the delay while switching from one file to the next, I open the next file with a different alias. While switching to the next file, I stop the first alias, and then play the second one.
Everything works great, until the user waits a while (i.e. 20 minutes) before playing the next (preloaded) file. In this situation the player has a 5 seconds delay before playing the new file, which has been preloaded for a while.
The question is, does winmm.dll put not-used-files in a "standby" mode? Do we need to activate it in certain time periods to reduce the delay? If yes how to do that?
I found a status called "parked" but this is never returned, and I can't find anything on the web describing it.
It would be a great help, if someone could help, cause there is not much documentation out there for this DLL.
MCI Commands
Thanks in advance!
I want to play many sound effect simultaneously from one audio file. So, I have an audio.wav file and I want to play it independently when I click a button. I have found similar question in here, but the solution not work for me because there is a lag between the sound. I have also try to use SharpDX from here but it still have a lag between the sound and sometimes it won't play.
In Windows Phone, I use SoundEffect and it works perfecly. Any solution for my problem?
Any ideas would be greatly appreciated. :)
I'm currently building a game in windows phone 7 using xna
i'm trying to get beat per minute from song that played in background song,
i also not quite sure if what i want is BPM, what i want is something like pace or tempo in music, faster the pace ,faster the sprites is moving. What i'm thinking right now, BPM is how much a frequency from music hits a range of defined constant, e.g 20 Mhz - 30 MHz,
Feel free to correct me if i'm wrong, i'm not really familiar with audio thing, i have tried using VisualizationData from MediaLibrary XNA, but after some googling they said that VisualizationData doesn't work with WP7, i also had tried it and the output is 256 length float array contains 0 value,,or if i could do some fft with it,i'll give it a try
Thank you...
Like you were saying, as for the beats you can't get it directly but you'll have to interpret this data. If you personally can preprocess this music and ship it with your title it would be your best bet
In XNA you really only have MediaPlayer.GetVisualizationData to work with. There isn't anything built in that allows you to predetermine this sort of thing. It's used like the following and gets you information about the different frequencies that are playing.
MediaPlayer.IsVisualizationEnabled = true;
VisualizationData visData = new VisualizationData();
MediaPlayer.GetVisualizationData(visData);
So how do you take this frequency stuff and make it worthwhile for your application? There's a great breakdown of how you can do this that's on the App Hub forums in this thread called "Audio Analysis" in the reply by jwatte. Essentially, you're going to look at the low frequencies and try to figure out when the beats are coming in. Nothing perfect, but hopefully you'll get something that you approve of.
Good luck!
I have 2 windowsMediaPlayer objects setup
Both objects have the same mp3 song file but when I play them at the same time they are out of sync by a few seconds. The code I call to play them looks like this
sound1.controls.play();
sound2.controls.play();
Is it just because one play method is executed before the other and thus one fast then the other. Is their anyway I could sync them? I have tired messing with the rate of one track to match the other, but not getting it prefect.
Thanks
You can't get this perfect, the players cannot start at the same time by design. You'll need to mix the two songs into a new song, the NAudio library can do this.