actionscript-3 - 如何在AS3中缓存音频流数据并访问它

标签 actionscript-3 flash caching audio stream

我正在AS3中流式传输MP3文件。一切工作正常(我可以玩),但我希望实现一个“搜索”栏。这意味着我将需要缓存文件(正在下载文件),然后在用户在歌曲中寻找特定时间时访问缓存的数据。

实际播放mp3流的代码:

function openStream( stream )
{
    var s:Sound = new Sound();
    var req:URLRequest = new URLRequest(stream);
    var context:SoundLoaderContext = new SoundLoaderContext(500, true);
    s.load(req, context);
    s.play();

}

那么在下载文件时如何缓存文件,然后从缓存中访问数据呢?

我知道这离完成一项琐碎的任务还很遥远,因此,如果您什至可以只提供一些教程/文档/文章的链接,我将不胜感激。

最佳答案

您不需要为此缓存声音。

只要声音对象存在于内存中,下载的声音数据就可用。

因此,您需要做的就是将声音对象放在函数范围之外。

播放功能还返回声音使用的当前SoundChannel。

private var snd:Sound = new Sound();
private var channel:SoundChannel;

function openStream( stream ) { 

     ... 

     channel = snd.play();
}

要实现搜索功能,您可以利用,
  • bytesLoaded(要知道下载了多少声音)
  • soundChannel.position(了解当前声音位置)
  • 关于actionscript-3 - 如何在AS3中缓存音频流数据并访问它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12721169/

    相关文章:

    javascript - 为 future 的网络应用程序寻找免费的、基于网络的 map API 建议

    node.js - 在nestjs中启动应用程序后是否可以更改CacheModule ttl?

    flash - 使用 "Dependency Injection"是什么意思?有没有要展示的 AS3 代码示例?

    android - 有谁知道 AIR 是否支持 iOS 或 Android 上的本地多人游戏?

    actionscript-3 - Actionscript 3 中的 Flash 搜索栏

    ios - 跟踪位图和矢量的问题 (AS3)

    缓存目录 : Failed to find configured root that contains 的 Android FileProvider

    spring - 缓存结果集

    actionscript-3 - Away3D 中的平铺和拉伸(stretch)

    actionscript-3 - 弹性 : Purepdf : Aligning paragraph text into the middle of a SimpleCell?