need help playing mp3 files within .NET application? - c#

My requirements are:
- play a mp3 file on button click
- provide a option to seek to a particular time
Almost all of the tutorials/resources that I came through, used ".wav" files to play the sound. But I need to play a ".mp3" file within the application, preferably without using any 3rd party library(NAudio, BASS, etc). I expect, it can be done using the available classes of the System.Media namespace.
What is the difference between a .wav file and .mp3 file? Are they encoded in different manner, and need different media plugins to be played?
So any help regarding mp3 files would be appreciated. Thanks.

I don't believe System.Media supports MP3 files. Assuming you are using Windows, a possible approach could be to use the Windows Media Player API by adding a COM reference to "Windows Media Player" in the Add Reference dialog. Then add a using directive:
using MP = MediaPlayer;
and then instantiate the class:
MP.MediaPlayer mediaPlayer = new MP.MediaPlayer();
You can then play music files by calling:
mediaPlayer.Open("filename.mp3");
This open method seems to automatically play the media file once it is opened, however there are explicit Play() and Stop() etc methods you can use to customise this behaviour to your liking.
The XNA framework also has ability to play music files using isn't allowed to contain spaces for some annoying reason so I recommend you use the Windows Media Player API if this is intended to be used on a PC.
I hope this has put you in the right direction!

Related

How to reproduce audio from a stream source

Thank you for your answer, I really appreciate it, and I have to share with you that it was a useful example, but in the following link is explained how to use it on Windows Phone 8.1 and how to create your own implementation of MSS.
http://video.ch9.ms/sessions/build/2014/2-528.pptx
What you’re doing is impossible.
Wave files aren’t media streams. You can’t dynamically change a .wav file and expect the MediaElement to pick those changes.
If you’re trying to play audio that you’re receiving from the network, or audio that you're generating dynamically from something else, then you need to play from your custom media stream source, not from a file.
The sample code is available here. The sample plays mp3; you’ll need to change it, wave audio is supported, with some limitations.

Playing a video file in server through WPF

I have a video file at my Server and the path to which resembles like "10.151.98.82/Medias/New/Videos/001.dat".
(Actually a video file but the extension is in .dat)
I have already built a WPF application which allows my users to enter the above Server URL and then let them to download it and then play it.
But my guess is that they need not wait till the entire file gets downloaded; just watch the files on the fly.
I have googled on video streaming but could not get a solid material to proceed on with.
[Sorry, if the question is naive or needs modification, i will be happy to do that or move to a relevant forum.]
Any pointers on how to do this is much appreciated.
Edit: This question talks about WCF service and WPF application. But, I dont' use a WCF Service. The video file has to be streamed from the server.
First try to play your file using VLC Player. it also have many advance streaming and Trans-coding Options. you can play, save and trans code simultaneously. Once you are able to Play your file in VLC Player than i would recommend to use VlcDotNet for wpf application. Tutorial for hosting VlcDotNet is available in downloads

How can I play any audio file(e.g. mp3,wav) in C#?

I have a question regarding with audio files.My question is:How can I play any audio file(e.g. mp3,wav) in C#? So if I press a button,I want to play to an audio file.
How can I do that? Can you tell me how it is done with a sample code?Lastly,I have used .Net Framework 4.0.
for that first you need to load wmp.dll from your system32 folder
Then you need to add COM component
Now you can do other things(creating player)
I have a tiny project (cutted NAudio version, only playback is left and only MP3 and WAV is supported) to play MP3 and WAV files. Do you still need it? I can upload it if you need to.
A full code example on how to play waves in c# forms apps can be found here
http://msdn.microsoft.com/en-us/library/ms173187%28v=VS.100%29.aspx
You can also play wave files using C# and the XNA Framework. But that may not serve your purpose, since that is primarily for games development.

Playing an MP4 in a zip file through a network location

I'm building a video system, and have came across a problem of accessing a video held in a remote location. Now predicament is that I don't want to mess around with the zip file by extracting the data, this would take too long from a user perspective and would rather be able to open video file directly from within side the zip. My question is, is this possible? The ability to open a file is not something I've found within the DotNetZip library.
The only solution I've found is pointing VideoLAN at the zip file and playing it from there. However, doing this programmatically is something I'm massively struggling with, through the VideoLan DotNet for WinForm & WPF C# plugin and it's lack of examples. Just wondering is there any alternative means?
Why dont you use the VLC ActiveX Directly ,just import the AxVlc.dll to you're project ,than you can select the VLC Plugin from Toolbox in VS (VLC Plugin v2 prefered).
Than you can do something vlc.playlist.add("FileName",Null,""); than use vlc.playlist.play(); version's under 0.9.9 works with Loop ,new version's you should build the Loop Function by you're self.
What's the reason of compressing video files? They are already compressed, and far better than zip can do.

Is it possible to transcode audio in C# using DirectSound?

I want to transcode a lot of audio from its source format to PCM without resampling or messing with the sample size. I figure if Windows Media Player can play the file and it doesn't use a legacy ACM codecs it must be using DirectSound to do so (this is on Windows XP and Windows Server 2k3). So is it possible to access DirectSound from C# and do so? I've tried searching the web but all the examples have been about playback which I have no interest in doing.
DirectSound is an audio playback API, you mean DirectShow. Windows Media player does use DirectShow to play audio files. In theory, all you need to do is build the same playback graph that media player uses, but replace the audio driver on the end with a .WAV writer filter.
This is somewhat easier to do in C++ code, since the DirectShow graph object is really designed to be called from C++, but with a good set of interop definitions, you can do this in C#.
There's http://directshownet.sourceforge.net/ for serious hacking with DirectShow in .NET, but that's probably overkill for your problem.
I would suggest getting a copy of GraphEdit if you don't already have one. You can use it to "prototype" direct show graphs interactively. drop a file into graphedit. then delete the filter on the end and replace it with a file writer filter.
One problem you will have is that there is no .WAV file writer filter in the default set of o DirectShow filters, you will have to find or write one.
If you just want to get the files converted, and could care less about learning how to write code using DirectShow, I would suggest that you just get a copy of Sound Forge (possibly even a demo version). It has a scripting language (C#,vb) that can be used to easily batch process most audio file formats.
Conversion to WAV can be done from the Windows command line using SoX (Sound eXchange, http://sox.sourceforge.net/). You could write a batch file or a C# application that calls SoX with the proper attributes. I'm not sure how WinAMP's feature works specifically, but it has a file writer output option built in as well. You can stream the entire playlist to wave files.
Have a look at this article on CodeProject about audio conversion here and here.

Categories