An unhandled exception of type 'System.ArgumentException' occurred in
NAudio.dll
Additional information: Unsupported sourceStream format
This is my current issue! I followed a tutorial on basic playing and pausing of a .wav file in Naudio, random .wav songs I found online throw this exception, yet the .wav that was provided in the video does not.
I can't seem to find an answer to this issue, but I am assuming it has something to do with bitrate of the different .wav files.
Can anyone confirm or deny this?
I too ran into this problem, and although am a complete coding beginner I found a solution that works.
I believe you are referring to giawa videos tutorial - 'C# Audio Tutorial 1 - Wave File with NAudio'
The problem arises when there is different compression methods used for the .wav file: https://support.microsoft.com/en-us/kb/89879
Not sure on the details, but i believe the tutorial uses PCM (stores absolute scale -1.0 - +1.0) where as I (we) used a wave file using ADPCM (stores the differences between samples).
I found the solution here: https://github.com/naudio/NAudio/wiki/Playing-an-Audio-File .
Basically the class wavefilereader cant actually read my (our) wave files. However another class MediaFoundationReader can (as well any media foundation codec installed on your computer.
Like I said, have no idea what i'm talking about, but it worked for me. Hopefully it helps someone, somewhere.
Related
Is it possible that the System.Media.SoundPlayer can not play Windows System Sounds found in c:\Windows\Media??
I have the code:
using (var soundPlayer =
new SoundPlayer(#"c:\Windows\Media\Landscape\Windows Notify.wav"))
{
soundPlayer.Play();
}
Yet when I run this code I get the error:
Sound API only supports playing PCM wave files.
Am I missing something? Is there a way to play these files from a WPF application? (without converting them to PCM)
The SystemSounds class contains the following predefined system sounds:
Asterisk
Beep
Exclamation
Hand
Question
So for example, to play the Stop:
System.Media.SystemSounds.Hand.Play();
All other sounds require you read the desired sound from the registry and play it with code like this:
SoundPlayer simpleSound = new SoundPlayer(#"c:\Windows\Media\Landscape\Windows Notify.wav");
This was an interesting question, but has a simple answer. After reading about this problem, I tried out your code and got the same problem, so then I searched online for a solution. While not finding an exact solution, I did find the SoundPlayer not playing any bundled windows sounds PCM wav files post here on StackOverflow that showed some code that played an audio file from the Windows\Media folder successfully.
I tried that code and it worked, so then I just had to work out why your example didn't work. I checked for any differences between the audio file that did play and your notify audio file in an audio editor, but they were both definitely WAV files.
I tried playing a different audio file from the Windows\Media\Landscape folder and got the same error. I then tried playing an audio file from a different sub folder in the Windows\Media folder and still got the same error. However, I then noticed that many of the folders in the Windows\Media folder had the same audio files in.
That got me thinking and I eventually realised that all of the audio files that are in these folders are actually in the Windows\Media folder directly. So you can play the sounds, but you just have to ignore the ones in the sub folders and play the ones from the Windows\Media folder. This will work:
SoundPlayer soundPlayer = new SoundPlayer(#"C:\Windows\Media\Windows Notify.wav");
soundPlayer.Play();
However, I can't tell you why we got that strange error, but I can only assume that the files in the folder could perhaps be some kind of links to the actual files in the Windows\Media folder and simply used by the operating system for grouping them into categories... or something similar.
"Landscape" refers to a Windows "Sound Scheme" and the wav files therein are utilized by the Windows OS. As you have already determined, those files cannot be used directly.
Comparison of the filesize of the Windows Notify.wav within the Landscape directory and the Windows Notify.wav file within the base Windows\Media directory is quite sizable; 222KB vs 25.5KB ---
If you go into the 'Sound' control panel applet and browse to 'Sounds' tab, you will see a dropdown list for "Sound Scheme:" and those additional folders within Windows\Media will be displayed in that list.
I don't have links to back this up, but after countless hours in dealing with Control Panel Sounds programmatically, I would venture to guess that the 'Sound Scheme' wav files just contain relevant data (perhaps effect data) that is consumed at runtime to play the modified versions of those sounds ... I could be quite wrong about that last part; it's just a guess. Regardless, you won't be able to use those sound scheme files directly within your code.
If you must play that "Landscape" version of the Notify wav, then I'd suggest playing the sound and saving it into a new wave file in an audio editor. You can add the wave file to your installer/deployment project to play it into the Windows\Media folder and call it directly the same way that you are already.
Since the sound seems to be in a compressed format, it has to be decompressed before you can play it using SoundPlayer. You can use Windows Audio Compression Manager to decompress the sound for playback:
https://msdn.microsoft.com/en-us/library/windows/desktop/dd742945(v=vs.85).aspx
However, that's rather complex to implement, so I discovered a nice library that does all that for you, NAudio:
http://naudio.codeplex.com/
Using NAudio seems to be slightly more involved than using System.Media.SoundPlayer, but it also appears to offer far more functionality.
I've searched for 2 days and I'm not getting how to convert the recorded wav file to an mp3 file; seen many questions even on stack overflow itself but no one gave the solution.
We can't execute System.Diagnostics.Process in Windows Phone.
there are many encoders like Lame, NAudio and so on; but don't know how to use that. .
recently I found example in codeproject named "mp3 Compressor", I tried use those classes but now i'm getting the below error,
Somebody please tell me how to achieve it. .
Why are you trying to do that?
I'm afraid you can't and mustn't do that. at least with tools like those ones you mention. Note, for example, that Zune transform a media before transfering it to the devices.
As an idea, you could upload your file to a service online and make the conversion there. It's more difficult of course and providing you have a host you can use.
I am new to direct show development. I am learning things about direct show. I am trying to write a method which plays some audio files. It works fine for many .mp3 files, but for some of my mp3 file the method RenderFile() of interface IGraphBuilder throws following exception
COMException occured : "Pins cannot connect due to not supporting the same transport."
My best guess is that I am missing some codec to play those files. Can anyone suggest what I am doing wrong. Is there any way to select a filter which can play those files. I am able to play those files with Windows Media Player, so I believe that I have required codecs installed.
Any help will be of great value.
Thanks in Advance.
This is a well known problem with MP3 files and standard DirectShow fitler reading them. The problem is that if a file has a big section with ID3 tags, the filter might give up skipping them to audio data and this makes the whole playback fail.
These files will still play fine if you open them starting with WM ASF Reader Filter. This assumes you build, or at least start building, the graph manually to override default building behavior.
I'd need to get the video duration of a mp4 video (video format AVC)
I'm using DirectShowLib 2.1
I downloaded a couple of codecs but I'm still getting code -2147220891 (an error code that I don't know what it means) doing
graphBuilder.RenderFile(filePath, null);
Any idea how to get the duration of this kind of video?
-2147220891 is 0x80040265 in hex. A search for that error code revealed this thread
0x80040265 isn't really "unknown". Strictly, it is VFW_E_UNSUPPORTED_STREAM, which means that your AVI files contain at least one stream (e.g., the video) that you do not have the right codec for.
So it looks like you still haven't found the right codec.
Does the file play in Windows Media Player or VLC (for example)?
If you just need the duration of a file, you can try using IMediaDet. I have an example of usage here: http://wpfmediakit.codeplex.com/SourceControl/changeset/view/41623#245585
A project I am currently working on at work requires the ability to convert videos from other formats to the WMV format. We need to be able to convert virtually any video format that is commonly used to a WMV format. I am looking for a solution allot like On2's flix engine converts other video types to .flv videos. I am aware of the encoder that windows offers, but it has a very limited list of video types that it can convert from. Please let me know if you have any suggestions or opinions, or recommendation of software I can use to do this. I need to be able to do the conversions in batch and I need to be able to do them programmatically with C#.
Have you had a look at ffmpeg?
It seems to be at the core of many open source video conversion utilities, so I imagine you could use it in the scenario you describe.
SUPER, the name is really covering the load!
Well, first you have to be able to decode the file format. You need to set this up with directshow, which is very hard to work with. You can take a look at the mediaportal project for a directshow file player written in C#. Instead of using the video renderer at the end of the directshow graph, you would reencode the video and audio and mux them into a .wmv file. This is a very involved project to get right. You essentially have to mimic a player's ability to play any format and handle failure.
I've been very satisfied using Quick Media Converter.