package com.sgcc.sgtms.comm
{
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;
import mx.collections.ArrayCollection;
import mx.core.SoundAsset;
/**
* 告警报警
* lws 2013-9-23
**/
public class AlarmSound
{
//告警报警,未确认告警
public var urlPath:String = "assets/sounds/alarm.mp3";
private static var _instance:AlarmSound = null;
private var soundFactory:Sound;
private var channel:SoundChannel;
private var soundList:ArrayCollection = new ArrayCollection();
/**
* 报警单态类实现
* lws 2013-9-23
**/
public static function getInstance():AlarmSound
{
if(!_instance)
{
_instance = new AlarmSound();
}
return _instance;
}
/**
* 开始报警
* lws 2013-9-23
**/
public function startSound(value:int):void
{
if(value > 0)
{
//关闭已经存在的声音对象
stopSound();
//加载声音对象
var request:URLRequest = new URLRequest(urlPath);
soundFactory = new Sound();
soundFactory.load(request);
//开始播放
channel = soundFactory.play();
//缓存声音对象
soundList.addItem(channel);
}
}
/**
* 停止报警
* lws 2013-9-23
**/
public function stopSound():void
{
//关闭已经存在的声音对象
for each(var eixtSound:SoundChannel in soundList)
{
eixtSound.stop();
soundList.removeItemAt(soundList.getItemIndex(eixtSound));
}
}
}
}
{
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;
import mx.collections.ArrayCollection;
import mx.core.SoundAsset;
/**
* 告警报警
* lws 2013-9-23
**/
public class AlarmSound
{
//告警报警,未确认告警
public var urlPath:String = "assets/sounds/alarm.mp3";
private static var _instance:AlarmSound = null;
private var soundFactory:Sound;
private var channel:SoundChannel;
private var soundList:ArrayCollection = new ArrayCollection();
/**
* 报警单态类实现
* lws 2013-9-23
**/
public static function getInstance():AlarmSound
{
if(!_instance)
{
_instance = new AlarmSound();
}
return _instance;
}
/**
* 开始报警
* lws 2013-9-23
**/
public function startSound(value:int):void
{
if(value > 0)
{
//关闭已经存在的声音对象
stopSound();
//加载声音对象
var request:URLRequest = new URLRequest(urlPath);
soundFactory = new Sound();
soundFactory.load(request);
//开始播放
channel = soundFactory.play();
//缓存声音对象
soundList.addItem(channel);
}
}
/**
* 停止报警
* lws 2013-9-23
**/
public function stopSound():void
{
//关闭已经存在的声音对象
for each(var eixtSound:SoundChannel in soundList)
{
eixtSound.stop();
soundList.removeItemAt(soundList.getItemIndex(eixtSound));
}
}
}
}