【问题标题】:Play sound from URI in c#.NET在 c#.NET 中从 URI 播放声音
【发布时间】:2016-10-12 15:06:54
【问题描述】:

有什么方法可以使用 soundcloud 流 URI 在我的 c#.NET 应用程序中播放音频?我找到了一种使用 Windows 8 手机执行此操作的方法:

new AudioTrack(new Uri("[your soundcloud uri]", UriKind.Absolute), "[Track Name]", "[Artist]", "[Album]", null)

但我在桌面 .NET 框架中找不到执行此操作的方法。有人可以对此有所了解吗?

【问题讨论】:

    标签: c# .net audio stream soundcloud


    【解决方案1】:

    由于 SoundCloud 使用 mp3 作为流格式,您可以使用 WMPLib。首先你需要添加它的引用(Project -> References -> Add Reference -> COM -> Windows Media Player)

    var wplayer = new WMPLib.WindowsMediaPlayer();
    wplayer.URL = "http://somewebsite.com/somedir/somefile.mp3";
    wplayer.controls.play();
    

    但在没有 Windows Media Player(如 Windows N、KN)的计算机上,您可能需要第三方库来播放 soundcloud 流。例如,NAudio

    ps:顺便说一句,WMPLib 的播放是异步的,所以需要注册到 StateChange 事件才能知道音乐是否结束。请参阅 MSDN 文章。

    参考:MSDN Article

    【讨论】:

      猜你喜欢
      • 2011-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-08
      • 1970-01-01
      • 1970-01-01
      • 2014-06-13
      • 2011-09-04
      相关资源
      最近更新 更多