我怎样才能玩融为一体pressed声音文件在C#中的一个可移植的方式? [英] How can I play compressed sound files in C# in a portable way?

查看:201
本文介绍了我怎样才能玩融为一体pressed声音文件在C#中的一个可移植的方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种便携式,而不是专利限制的方式来播放COM pressed在C#/ .NET声音文件?我想打短顺口溜的声音在各种活动存在的程序中。

System.Media.SoundPlayer 只能处理WAV,但这些通常以大的下载apllication嵌入。 MP3保护与专利,因此,即使有一个全面管理的德codeR /播放器也不会免费再分发。提供最好的格式似乎是的Ogg Vorbis,但我没有运气得到任何C#Vorbis的图书馆合作,(我成功地提取原始的PCM的 csvorbis ,但我不知道怎么算账播放)。

我不是要分发的任何可执行文件与我的应用程序,也不依赖的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的声音播放导致失真

已过期:

System.Diagnostics.Process.Start(fullPath.mp3);

我觉得很奇怪,但<一个href="http://stackoverflow.com/questions/35896/how-can-i-play-com$p$pssed-sound-files-in-c-in-a-portable-way#35987">method黛娜提到的实际工作。不过,我在想打短顺口溜的声音就在节目中发生的各种事件,我不想每次我需要做一个时间启动用户的媒体播放器平!声音。

对于code项目的链接 - 这是不幸的是只有一个的P / Invoke包装

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:

System.Diagnostics.Process.Start("fullPath.mp3");

I am surprised but the method Dinah mentioned actually works. However, I was thinking about playing short "jingle" sounds on various events occurring in the program, I don't want to launch user's media player each time I need to do a 'ping!' sound.

As for the code project link - this is unfortunately only a P/Invoke wrapper.

这篇关于我怎样才能玩融为一体pressed声音文件在C#中的一个可移植的方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆