I'm doing a sample which will run mp3 files which are selected by the user. I
want to calculate the playing time of the file (e.g. 00:05:32). How can I calculate the playing time?
You could use TagLib Sharp
It exposes TagLib.AudioProperties.Duration
For Alvas.Audio library see code below
using (Mp3Reader mr = new Mp3Reader(File.OpenRead("len.mp3")))
{
int durationMS = mr.GetDurationInMS();
TimeSpan durationTS = TimeSpan.FromMilliseconds(durationMS);
}
You suggest in the tag that you're doing this in C#. This question deals with it:
Finding MP3 length in C#
And there's some code for reading the MP3 header and extracting relevant information (like the length) here:
http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=79
I believe the Windows Media API (or windows mixer api or something, I can't recall the exact name) has a way to open and read sound files like mp3 and maybe get the time from it too. As an added bonus, by using that API you can open any audio format that will work in say Windows Media Player, so you're not limited to just mp3's.
Related
How can I get media element source (mp3 file) duration in windows phone 8 without playing the file.
Thanks,
There are at least 2 ways of doing this I can think of at the moment, however I´d recommend you to do it in this way:
first is to read it directly from file's MusicProperties by using GetMusicPropertiesAsync():
You might need to adapt the code a little bit, tell me if there´s something else you do need.
Hello I am working on video files and would like to learn video's length, frame width and height, and total bitrate. I have seen solutions for ID3 tags but they don't seem working for movies(.mov extension)
Find and download/buy ISO/IEC 14496-12 (MPEG-4 Part 12)
The mvhd and tkhd boxes (and possibly others... it's been a while!) will give you the information you're looking for. The MOV file format is quite easy to parse.
Provided that the file is playable within DirectShow, you can build a pipeline for this file and without running it check the pipeline properties to find out details like duration is resolution. This method is not specific to .MOV and works out well for other formats. In C# you typically interface to DirectShow via DirectShow.NET.
See related:
Grab frame from .mov file using DirectShow.net
Getting MP4 File Duration with DirectShow
how to get the duration from a mp4 media file by C#
In my opionion the best way is use of MediaInfo. It not requires any additional codecs installed etc.
See my answer in this post:
unable to load MediaInfo Library
Is it possible to capture video and audio in Silverlight5 and save it as movie in any video format?
Silverlight 5 can automatically detect video and audio capture devices, which you can open operations on using the System.Windows.Media.CaptureDeviceConfiguration class and associated classes.
http://chris.59north.com/post/Audio-recording-and-encoding-in-Silverlight.aspx has info on how to use those classes to save the audio to a Stream (as well as compressing it), which you can then save to disk.
http://www.dotnetfunda.com/articles/article1751-how-to-access-a-video-and-snap-a-picture-from-webcam-in-silverlight.aspx has similar info on how to access video and save images from webcams on to disk using Silverlight.
Pro Silverlight 5 in C# (excerpt on Google Books) has more information on how to do this.
I have been doing quite a lot of searching and I have yet to find any samples of anyone actually saving video. The best I have been able to come up with is saving a sequence of images. That doesn't really sound like a good solution
Is there anyway that I can record sound from a microphone using c# .net
What is the best option if i have to save the audio online in terms of the file occupying storage space.
Any particular format that the file should be saved in for optimum output.
I think you have to use either a small flash application or a silverlight application to do the actual recording. Then you upload the file to your application using a web service or similar.
And mp3 is sort of a standard file format for sound on the web. So I'd go with that.
Have a look at these projects:
http://www.codeproject.com/KB/winsdk/SoundRecord.aspx
http://www.codeproject.com/Articles/67568/Creating-a-Sound-Recorder-in-C-and-Csharp.aspx
http://www.codeproject.com/KB/audio-video/cswavrec.aspx
What is the best option if i have to save the audio online in terms of the file occupying storage space.
May be real media (.rm).
Any particular format that the file should be saved in for optimum output.
Not sure but I think that depends on
your player.
You might also be interested in ffmpeg for converting the media and its c# wrapper library.
I'm trying to write a Silverlight application that reads a media file from a database (most likely a .mpeg or .mpg) and play it on the fly using either a Silverlight MediaPlayer or ExpressionMediaPlayer. When I try using Expression Media Player it plays .wmv and .mp4 files but NOT .mpeg or .mpg file extensions. Is this even possible? If so, HOW?!
I tried going a different route originally where I wrote a Service to Encode the file using a LiveJob and then play it on the ExpressionMediaPlayer from the port using mms://localhost:8080 but I couldn't figure out how to use that to Play/Pause the video. It just ran through once and stopped. Any suggestions on that?
I'm using Expression Encoder 3 & Silverlight 4 by the way.
i think you're out of luck, check out this page from msdn.
You are going to have to re-encode the file if you want it to play in Silverlight.