问题描述
有没有一种便携式,而不是专利限制的方式来播放COM pressed在C#/ .NET声音文件?我想打短顺口溜的声音在各种活动存在的程序中。
System.Media.SoundPlayer 只能处理WAV,但这些通常以大的下载apllication嵌入。 MP3保护与专利,因此,即使有一个全面管理的德codeR /播放器也不会免费再分发。提供最好的格式似乎是的Ogg Vorbis,但我没有运气得到任何C#Vorbis的图书馆合作,(我成功地提取原始的PCM的,但我不知道怎么算账播放)。
我不是要分发的任何可执行文件与我的应用程序,也不依赖的P / Invoke,作为项目至少应该在Windows和Linux上运行。我很好捆绑.NET程序集,只要他们的许可证是兼容GPL。
[这个问题是一个跟进到邮件邮件列表单-dev邮件列表讨论去年同期]
我终于从 BrokenGlass重新上这个话题,并使用帮助写波头,更新csvorbis。我已经添加了一个<一个href="https://github.com/mono/csvorbis/blob/master/OggDe$c$cr/OggDe$c$cStream.cs">OggDe$c$cStream可以传递给 System.Media.SoundPlayer
来简单地播放任何(兼容)的Ogg Vorbis流。用法示例:
使用(var文件=新的FileStream(oggFilename,FileMode.Open,FileAccess.Read))
{
VAR球员=新的SoundPlayer(新OggDe codeStream(文件));
player.PlaySync();
}
兼容模式在这种情况下意味着它的工作时,我尝试过了。去codeR为全面管理,对微软的.Net工作正常 - 的那一刻,似乎有一个回归Mono的声音播放
导致失真
已过期:
。Is there a portable, not patent-restricted way to play compressed sound files in C# / .Net? I want to play short "jingle" sounds on various events occuring in the program.
System.Media.SoundPlayer can handle only WAV, but those are typically to big to embed in a downloadable apllication. MP3 is protected with patents, so even if there was a fully managed decoder/player it wouldn't be free to redistribute. The best format available would seem to be OGG Vorbis, but I had no luck getting any C# Vorbis libraries to work (I managed to extract a raw PCM with csvorbis but I don't know how to play it afterwards).
I neither want to distribute any binaries with my application nor depend on P/Invoke, as the project should run at least on Windows and Linux. I'm fine with bundling .Net assemblies as long as they are license-compatible with GPL.
[this question is a follow up to a mailing list discussion on mono-dev mailing list a year ago]
I finally revisited this topic, and, using help from BrokenGlass on writing WAVE header, updated csvorbis. I've added an OggDecodeStream that can be passed to System.Media.SoundPlayer
to simply play any (compatible) Ogg Vorbis stream. Example usage:
using (var file = new FileStream(oggFilename, FileMode.Open, FileAccess.Read))
{
var player = new SoundPlayer(new OggDecodeStream(file));
player.PlaySync();
}
'Compatible' in this case means 'it worked when I tried it out'. The decoder is fully managed, works fine on Microsoft .Net - at the moment, there seems to be a regression in Mono's SoundPlayer
that causes distortion.
Outdated:
这篇关于我怎样才能玩融为一体pressed声音文件在C#中的一个可移植的方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!