I'm working on an application that will read in file paths and play audio files. I'm trying to keep this as simple as possible--by using existing codecs and free/open utilities. I'd like some suggestions on the best way to do this. I've had two ideas, both involving FFmpeg:
Create a simple GUI that allows the user to read pass in file(s) to be played, and then a ffplay.exe process is run in the background to play the file(s).
Go more in-depth by just using libavcodec and basing my project off the functionality available with that.
There are only a few main goals I have for this.
Be able to read in and play multiple files without breaks between them
Start playback at an arbitrary spot (based on a percent of total duration) within the track
Stop playback after an arbitrary amount of time, and move to the next track
Which of my two methods seem the most practical for this project? Is there a better--or perhaps less feature-intensive--alternative to FFmpeg that you would suggest.
This is for a Windows application written in C#.
Edit: One of the reasons that I started with FFmpeg is that it can handle many file types, notably MP3, AAC, Flac.
Edit2: If the use of libavcode.dll is the best option, it would also be helpful to get some info on implementing that in C#.
The BASS audio library has C# bindings and works very well with common audio formats (e.g. MP3) with plug-ins for other formats (e.g. AAC).
However, for commercial development, you require a license to use BASS.
Related
Is there a way to edit videos using c# without using a media library eg. Microsoft Expression Encoder etc.
Just need to be able to cut out unwanted parts or insert other videos into a specified time of the original video.
Can I edit the raw video file by perhaps converting it into a binary file and then cutting/pasting the code?
Most video formats have a container and a codec--that might be a good place to start
http://www.pitivi.org/manual/codecscontainers.html
If one were interested in implementing a program modifying video sans libraries a good place to start might be looking at the existing open source video libraries(eg FFMPEG https://www.ffmpeg.org/download.html ) as a reference
No there is no way to edit a video without using anything that would be considered a "library". You either must write your "library" or use a existing 3rd party one.
The only thing that could possibly not be thought of as a "library" is a full external tool that does what you want and your code would just be a front end GUI for it. For example writing a GUI front end for FFmpeg.
I am developing application that receives media content(.mp3/.mp4/.avi) in form of bytes.
However, as WPF doesn't support playing media from stream, So I started with WMP.dll.
I am creating class library that receives media in form of bytes and media format and play media accordingly.
Referring Creating the WMP Programmatically, however, I didn't find method to pass bytes stream.
So My question is how do I play media from bytes using wmp.dll?
Edit: I am using WMP.dll using COM located at C:\WINDOWS\system32\wmp.dll
I've been through this process a long time ago ...
Basically I would advise you NOT to go down the WMP route at all. It's heavy, cumbersome and not very nice to work with. I encountered lots of issues along the way basically. Least of all it being feature rich (which it isn't).
The best solution I found and the one I'm still using now is a library called BASS from Un4SeenDevelopments.
This library is tiny < 100k and basically it's awesome. Never had a problem with it and it has it's own .NET wrapper that is a free download from the site.
The support is amazing and the compatibility via a massive selection of plugins and additional libraries is staggering.
Highly recommended for what you want to do.
"BASS is an audio library for use in software on several platforms. Its purpose is to provide developers with powerful and efficient sample, stream (MP3, MP2, MP1, OGG, WAV, AIFF, custom generated, and more via OS codecs and add-ons), MOD music (XM, IT, S3M, MOD, MTM, UMX), MO3 music (MP3/OGG compressed MODs), and recording functions. All in a compact DLL that won't bloat your distribution."
I’m making an audio synthesizer and I’m having issues figuring out what to use for audio playback. I’m using physics and math to calculate the source waveforms and then need to feed that waveform to something which can play it as sound. I need something that can 1) play the waveforms I calculate and 2) play multiple sounds simultaneously (like holding one key down on a piano while pressing other keys). I’ve done a fair bit of research into this and I can’t find something that does both of those things. As far as I know, I have 5 potential options:
DirectSound. It can take a waveform (a short[]) as a parameter and play it as sound, and can play multiple sounds simultaneously. But it won’t work with .NET 4.5.
System.Media.SoundPlayer. It works with .NET 4.5 and has better quality audio than Direct Sound, but it has to play sound from a .wav file and cannot play multiple sounds at once (nor can multiple instances of SoundPlayer). I ‘trick’ SoundPlayer into working by translating my waveform into .wav format in memory and then send SoundPlayer a MemoryStream of the in-memory .wav file. Could I potentially achieve control over the playback by altering the stream? I cannot append bytes to the stream (I tried) but I could potentially make the stream an arbitrary size and just re-write all the bytes in the stream with the next segment of audio data every time the end of the stream is reached.
System.Windows.Controls.MediaElement. I have not experimented with this yet, but from MSDNs documentation I don’t see a way to send it a waveform in memory without saving it to disk first and then reading it; I don’t think I can send it a stream.
System.Windows.Controls.MediaPlayer. I have not experimented with this either, but the documentation says it’s meant to be used as a companion to some kind of animation. I could potentially use this without doing any real (user-perceivable) animation to achieve my desired effect.
An open source solution. I’m hesitant to use an open source solution as I find they are typically poorly documented and not very maintainable, but I am open to ideas if there is one out there that is well documented and can do what I need.
Can anyone offer me any guidance on this or how to create flexible audio playback?
http://naudio.codeplex.com , without a doubt. Mark is a regular here on SO, the product is well alive, there are good code examples.
It works. We built some great stuff with it.
1.There are some file formats (suppose a real audio file? (.ra)) which VLC can play butWindows Media Player (Default) can't. How can I find out if there is a player in the system that can play the file format I want?
2.Additionally, is there a way to embed such a player in my (C#) application in a generic way?
It is a bit complicated but I can give you a start point (the code would be a bit too long to write it now), so here is what I think.
You just go and search in the
HKEY_CLASSES_ROOT
hive for the extension of the file (in your case it will be .ra). If you find such key, you will either have a subkeys that will help you determine what software has been used to open them or using the "Content Type" string value, you perform another search in the HKEY_CLASSES_ROOT where you will again have keys that will say what software opens this kind of content.
So you need to use the classes that deal with the Registry (asuming you want to do this programatically).
About your second question: I don't think there is a generic way to embed any player in your application. It's because not every player will provide some API to attach to, you won't have a contract to rely on and a lot of other problems. You may have some success with the Windows API but I doubt it will cover all the scenarios you will end up having to support.
You have few choices here:
Do everything you can with Media Player and if the file format is
not supported - offer the user to open it with the default player
(simple call to the System.Diagnostics.Process.Start with the
filename should be enough for Windows to start the appropriate
program) (easiest approach).
Write your own player, which can read / transform from various
formats. You should be able to find a lot of the formats supported
by different libraries in Internet or at least find their RFCs (the
most tough you can do).
Use some library or software to convert the file types you cannot play in the background and run them with the media player as if they were supported (probably a good way to achieve maximum result with minimum efforts), you can again fire some processes in the background with the System.Diagnostics.Process.Start, hiding them from the user and load the media after it was converted. Video sites like YouTube do something like this when you upload a file - they put it on another process so it can be converted and then the video is available in common format (in most cases it is flash video - flv, I believe).
I am currently playing around in c#, and I would like to have some music play in the background and to have other little sounds happen when a user hits a button or when other little actions take place. (specifically, I am making a small game, using mogre3d, and I am just to the point in which I need to add a little sound).
1) Is there a way already built in to c# to play multiple wav files at the same time? I have tried using System.Media.SoundPlayer, but that can only play one wav file at a time (and I can not set the volume in which it is played).
2) What is the best/easiest way to play multiple sounds at a time and to be able to set each of the sounds volume?
I am dreadfully new to C#, and I am sure their must be a simple solution that I am just not seeing. It does not need to be wav, it can easily be mp3/et al. but the simpler the solution the better.
Thanks kindly for your time!
Fast
Change overall volume with that method: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/42b46e40-4d4a-48f8-8681-9b0167cfe781 and you can play .wav files simultaneously with separate SoundPlayer instances.
Better and seperate Volumes
I would use Bass.Net. Good documentation and simple.
You can play multiple .wav files simultaneously with the System.Media.SoundPlayer class: for this, just create an instance of soundPlayer for each .wav file you wish to play. But you cannot set the volume independently this way.
If you want more functionalities with audio files, I recommend you check the NAudio library.