2010-02-25 74 views
1

在我的AS2 Flash遊戲中,我會播放多個聲音文件,然後等待「onSoundComplete」消息/函數再繼續。Flash AS2 - 處理丟失的聲卡

問題是如果系統中沒有聲卡(或者它在設備管理器中被禁用) - 一切都像它工作(沒有錯誤,onLoad處理程序獲取「真」) - 但聲音從未真正獲取發揮,因此,我的事件永遠不會被觸發。

我已經計劃通過掛鉤我的聲音代碼來解決這個問題,如果我沒有檢測到聲卡,只需啓動計時器等待幾秒鐘,然後手動啓動「onSoundComplete」函數。

唯一的問題是,我無法可靠地找到一種方法來確定系統中是否有聲卡!

順便說一句 - AS3似乎是由傳回一個空的SoundChannel很好地處理這個問題 - 不幸的是,我停留在AS2.0

+0

現在,我可以找出系統是否有聲音的唯一可靠方法是以低音量播放短小的聲音文件,並檢查是否有onSoundComplete函數觸發。 這樣的黑客使我的一小部分死亡。 – n3wtz 2010-02-25 21:13:17

回答

1

您應該能夠使用System.capabilities

下面是一個例子音頻:

var userAudio:Boolean = System.capabilities.hasAudio; 
trace("YOUR SYSTEM HAS AUDIO:"); 
trace(userAudio); 

這裏是所有屬性的來源:http://www.actionscript.org/forums/showthread.php3?t=39727

// Camera and Microphone check 
var userCamMic:Boolean = System.capabilities.avHardwareDisable; 
trace("YOUR CAMERA AND MICROPHONE ARE ENABLED:"); 
trace(userCamMic); 
// Flash player supports communication to Accessibility Aids 
var userAccess:Boolean = System.capabilities.hasAccessibility; 
trace("YOUR FLASH PLAYER SUPPORTS COMMUNICATION TO ACCESSIBILITY AIDS:"); 
trace(userAccess); 
// Checking to see if you have audio 
var userAudio:Boolean = System.capabilities.hasAudio; 
trace("YOUR SYSTEM HAS AUDIO:"); 
trace(userAudio); 
// Checking to see if you have an audio encoder for streaming 
var userAudioEnc:Boolean = System.capabilities.hasAudioEncoder; 
trace("YOUR SYSTEM HAS AN AUDIO ENCODER, THUS ALLOWING STREAMING:"); 
trace(userAudioEnc); 
// Checking to see if your system has embedded video capabilities 
var userEmbVideo:Boolean = System.capabilities.hasEmbeddedVideo; 
trace("YOUR SYSTEM ALLOWS FOR EMBEDDED VIDEO:"); 
trace(userEmbVideo); 
// Checking to see if your system has an MP3 decoder 
var userMP3:Boolean = System.capabilities.hasMP3; 
trace("YOUR SYSTEM HAS AN MP3 DECODER:"); 
trace(userMP3); 
// Checking to see if your system supports printing 
var userPrint:Boolean = System.capabilities.hasPrinting; 
trace("YOUR SYSTEM SUPPORTS PRINTING:"); 
trace(userPrint); 
// Checking to see if your system supports development of screen broadcast 
// applications to be run through Flash Communication Server 
var userScrnBrd:Boolean = System.capabilities.hasScreenBroadcast; 
trace("YOUR SYSTEM SUPPORTS DEVELOPMENT OF SCREEN BROADCAST APPLICATIONS TO BE RUN 
THROUGH FLASH COMMUNICATION SERVER:"); 
trace(userScrnBrd); 
// Checking to see if your system supports playback of screen broadcast 
// applications that are running from Flash Communication Server 
var userScrnPlay:Boolean = System.capabilities.hasScreenPlayback; 
trace("YOUR SYSTEM SUPPORTS PLAYBACK OF SCREEN BROADCAST APPLICATIONS THAT ARE 
RUNNING FROM FLASH COMMUNICATION SERVER:"); 
trace(userScrnPlay); 
// Checking to see if your system can play streaming audio 
var userStrmAud:Boolean = System.capabilities.hasStreamingAudio; 
trace("YOUR SYSTEM CAN PLAY STREAMING AUDIO:"); 
trace(userStrmAud); 
// Checking to see if your system can play streaming video 
var userStrmVid:Boolean = System.capabilities.hasStreamingVideo; 
trace("YOUR SYSTEM CAN PLAY STREAMING VIDEO:"); 
trace(userStrmVid); 
// Checking to see if your system can encode streaming video 
var userVidEnc:Boolean = System.capabilities.hasVideoEncoder; 
trace("YOUR SYSTEM CAN ENCODE STREAMING VIDEO:"); 
trace(userVidEnc); 
// Checking to see if your player is officially released (false) or a debugging version (true) 
var userDebug:Boolean = System.capabilities.isDebugger; 
trace("YOUR PLAYER IS A DEBUGGING VERSION:"); 
trace(userDebug); 
// What language is your player running 
var userLang:String = System.capabilities.language; 
trace("YOUR PLAYER IS RUNNING ON THIS LANGUAGE (see Actionscript 'Reference' for language list. 
Example: 'en' is English):"); 
trace(userLang); 
// Checking to see if player is attempting to read anything from hard disk 
var userLocFile:Boolean = System.capabilities.localFileReadDisable; 
trace("YOUR PLAYER IS ATTEMPTING TO READ FROM YOUR HARD DISK:"); 
trace(userLocFile); 
// Checking to see the manufacturer of your Flash player 
var userManu:String = System.capabilities.manufacturer; 
trace("YOUR FLASH PLAYER IS MANUFACTURED BY:"); 
trace(userManu); 
// Checking to see what operating system user is running 
var userOS:String = System.capabilities.os; 
trace("YOUR OPERATING SYSTEM IS:"); 
trace(userOS); 
// Checking the pixel aspect ratio of user screen 
var userPAR:Number = System.capabilities.pixelAspectRatio; 
trace("THE PIXEL ASPECT RATIO OF YOUR SCREEN IS:"); 
trace(userPAR); 
// Checking to see what player the user system is using 
var userPlayType:String = System.capabilities.playerType; 
trace("THE PLAYER YOUR SYSTEM IS RUNNING IS:"); 
trace(userPlayType); 
// Checking to see what color user screen is running 
var userScrnCol:String = System.capabilities.screenColor; 
trace("YOUR SYSTEM IS RUNNING THIS COLOR (color, gray, bw):"); 
trace(userScrnCol); 
// Checking to see what the users screen DPI is 
var userDPI:Number = System.capabilities.screenDPI; 
trace("YOUR SCREEN DPI (DOTS PER INCH) IS:"); 
trace(userDPI); 
// User screen resolution 
var userScreenX:Number = System.capabilities.screenResolutionX; 
var userScreenY:Number = System.capabilities.screenResolutionY; 
trace("YOUR MONITOR RESOLUTION IS:"); 
trace(userScreenX+" x "+userScreenY); 
// Creating URL code for users system capabilites 
var userServStr:String = System.capabilities.serverString; 
trace("THE URL CODE FOR YOUR USER SYSTEM CAPABILITIES IS:"); 
trace(userServStr); 
// Checking to see what Flash player version user is running 
var userVersion:String = System.capabilities.version; 
trace("YOUR FLASH PLAYER VERSION IS:"); 
trace(userVersion); 
// Checking to see if user has disabled windowless mode 
var userWinDis:Boolean = System.capabilities.windowlessDisable; 
trace("YOU HAVE DISABLED WINDOWLESS MODE:"); 
trace(userWinDis); 
// Checking to super domain or exact domain is set 
var userExacSet:Boolean = System.exactSettings; 
trace("YOU HAVE SUPER DOMAIN SETTINGS:"); 
trace(userExacSet); 
+0

奇怪的是,即使我在設備管理器中禁用了聲卡,System.capabilities.hasAudio也是「true」。 – n3wtz 2010-02-25 18:58:25

+0

此答案無效,因爲System.capabilities.hasAudio對桌面玩家而言始終爲真 - System.capabilities報告* player *的功能,而不是系統。請參閱http://stackoverflow.com/questions/4511146/check-if-users-flash-player-has-audio-capabilities-capabilities-hasaudio – Sam 2011-05-27 00:32:49