Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Flash无缝播放来自不同文件的音轨?_Flash_Actionscript 3_Networking_Audio - Fatal编程技术网

使用Flash无缝播放来自不同文件的音轨?

使用Flash无缝播放来自不同文件的音轨?,flash,actionscript-3,networking,audio,Flash,Actionscript 3,Networking,Audio,我的http服务器上有一些音频文件,我想在ActionScript3中编写一个Flash客户端来加载这些音频文件并顺利播放它们。当然,我可以创建一个声音对象,然后通过.load()和URL请求加载它。但是为了节省带宽,我更喜欢按需加载音频文件块。例如,有一个音频文件,比如说100MB。如果我们尝试在用户打开页面时尽可能快地加载 <--------- 100MB -----------> 下载可能会在几分钟内完成,但比方说,如果用户中途停止收听,那么一开始就加载整个配乐是一种浪费

我的http服务器上有一些音频文件,我想在ActionScript3中编写一个Flash客户端来加载这些音频文件并顺利播放它们。当然,我可以创建一个声音对象,然后通过.load()和URL请求加载它。但是为了节省带宽,我更喜欢按需加载音频文件块。例如,有一个音频文件,比如说100MB。如果我们尝试在用户打开页面时尽可能快地加载

<--------- 100MB ----------->

下载可能会在几分钟内完成,但比方说,如果用户中途停止收听,那么一开始就加载整个配乐是一种浪费

<--------- 100MB ----------->
   ^--- user may stop here

^---用户可以到此为止
为了解决这个问题,我认为最好将大的音频文件分成小块,根据需要加载和播放它们

<--- 10MB ---><--- 10MB ---><--- 10MB ---> ...
                                     ^--- user current position
。。。
^---用户当前位置
我想设计播放器,让它一块一块地加载音频,并且只在接近当前块末尾时加载


问题来了-如何加载这些块并顺利播放它们?我可能可以为每个块创建声音对象。但是如何无缝地播放它们呢?

您可能会想使用它们,并在那里看到它们。一旦你加载了一个声音,你就可以播放这个声音,存储位置,并获取长度来找出剩下的播放时间。从那里,可能会发送一个事件来加载下一个声音。源自第二个示例(必须将其放在类结构中):


你可能会想使用,并看到那里,和。一旦你加载了一个声音,你就可以播放这个声音,存储位置,并获取长度来找出剩下的播放时间。从那里,可能会发送一个事件来加载下一个声音。源自第二个示例(必须将其放在类结构中):

// Note that you will need some type of sound management 
// class to listen to events and to play the series of sounds.  
// That is not documented here.

import flash.events.Event; 
import flash.media.Sound; 
import flash.net.URLRequest; 

var snd:Sound = new Sound(); 
var req:URLRequest = new URLRequest("sound1.mp3"); 
snd.load(req); 

var channel:SoundChannel; 
channel = snd.play(); 
addEventListener(Event.ENTER_FRAME, onEnterFrame); 
channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete); 

function onEnterFrame(event:Event):void 
{ 
    var estimatedLength:int =  
        Math.ceil(snd.length / (snd.bytesLoaded / snd.bytesTotal)); 
    var playbackPercent:uint =  
        Math.round(100 * (channel.position / estimatedLength)); 
    if( playbackPercent > 75) 
        loadNextSound();
    trace("Sound playback is " + playbackPercent + "% complete."); 
} 

function loadNextSound() 
{
    // In whatever sound manager class you create, 
    // listen for this "loadNextSound" event, 
    // and start the next sound loading when it occurs.
    dispatchEvent(new Event("loadNextSound"));

}


function onPlaybackComplete(event:Event) 
{ 
    trace("The sound has finished playing."); 
    removeEventListener(Event.ENTER_FRAME, onEnterFrame); 
}