| 1 |
// |
|---|
| 2 |
// Licensed under the MIT License |
|---|
| 3 |
// |
|---|
| 4 |
// Copyright (C) 2008 TAKANAWA Tomoaki (http://nutsu.com) and |
|---|
| 5 |
// Spark project (www.libspark.org) |
|---|
| 6 |
// |
|---|
| 7 |
// Permission is hereby granted, free of charge, to any person obtaining a copy |
|---|
| 8 |
// of this software and associated documentation files (the "Software"), to deal |
|---|
| 9 |
// in the Software without restriction, including without limitation the rights |
|---|
| 10 |
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|---|
| 11 |
// copies of the Software, and to permit persons to whom the Software is |
|---|
| 12 |
// furnished to do so, subject to the following conditions: |
|---|
| 13 |
// |
|---|
| 14 |
// The above copyright notice and this permission notice shall be included in |
|---|
| 15 |
// all copies or substantial portions of the Software. |
|---|
| 16 |
// |
|---|
| 17 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|---|
| 18 |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|---|
| 19 |
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|---|
| 20 |
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|---|
| 21 |
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|---|
| 22 |
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|---|
| 23 |
// THE SOFTWARE. |
|---|
| 24 |
// |
|---|
| 25 |
|
|---|
| 26 |
package snapfit.media |
|---|
| 27 |
{ |
|---|
| 28 |
import flash.media.Sound; |
|---|
| 29 |
import flash.media.SoundLoaderContext; |
|---|
| 30 |
import flash.media.SoundTransform; |
|---|
| 31 |
import flash.media.SoundChannel; |
|---|
| 32 |
import flash.net.URLRequest; |
|---|
| 33 |
import snapfit.events.adapters.FSoundAdapter; |
|---|
| 34 |
|
|---|
| 35 |
/** |
|---|
| 36 |
* FSound |
|---|
| 37 |
* |
|---|
| 38 |
* @author nutsu |
|---|
| 39 |
*/ |
|---|
| 40 |
public class FSound extends Sound |
|---|
| 41 |
{ |
|---|
| 42 |
private var _adapter:FSoundAdapter; |
|---|
| 43 |
|
|---|
| 44 |
private var _channel:SoundChannel; |
|---|
| 45 |
private var _channel_flg:Boolean; |
|---|
| 46 |
|
|---|
| 47 |
/** |
|---|
| 48 |
* FSound |
|---|
| 49 |
* |
|---|
| 50 |
* @param stream |
|---|
| 51 |
* @param context |
|---|
| 52 |
*/ |
|---|
| 53 |
public function FSound( stream:URLRequest = null, context:SoundLoaderContext = null ) |
|---|
| 54 |
{ |
|---|
| 55 |
super( stream, context ); |
|---|
| 56 |
_adapter = new FSoundAdapter( this ); |
|---|
| 57 |
_channel_flg = false; |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
public function get event():FSoundAdapter |
|---|
| 61 |
{ |
|---|
| 62 |
return _adapter; |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
override public function play( startTime:Number = 0, loops:int = 0, sndTransform:SoundTransform = null ):SoundChannel |
|---|
| 66 |
{ |
|---|
| 67 |
_channel = super.play( startTime, loops, sndTransform ); |
|---|
| 68 |
if ( _channel ) |
|---|
| 69 |
_channel_flg = true; |
|---|
| 70 |
return _channel; |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
//---------------------------------------------------------------------------------------------- SoundChannel |
|---|
| 74 |
|
|---|
| 75 |
/** |
|---|
| 76 |
* SoundChannel |
|---|
| 77 |
*/ |
|---|
| 78 |
public function get channel():SoundChannel { return _channel; } |
|---|
| 79 |
|
|---|
| 80 |
/** |
|---|
| 81 |
* SoundTransform |
|---|
| 82 |
*/ |
|---|
| 83 |
public function get soundTransform():SoundTransform |
|---|
| 84 |
{ |
|---|
| 85 |
if ( _channel_flg ) |
|---|
| 86 |
return _channel.soundTransform; |
|---|
| 87 |
else |
|---|
| 88 |
return null; |
|---|
| 89 |
} |
|---|
| 90 |
|
|---|
| 91 |
/** |
|---|
| 92 |
* position |
|---|
| 93 |
*/ |
|---|
| 94 |
public function get position():Number |
|---|
| 95 |
{ |
|---|
| 96 |
if ( _channel_flg ) |
|---|
| 97 |
return _channel.position; |
|---|
| 98 |
else |
|---|
| 99 |
return NaN; |
|---|
| 100 |
} |
|---|
| 101 |
|
|---|
| 102 |
/** |
|---|
| 103 |
* leftPeak |
|---|
| 104 |
*/ |
|---|
| 105 |
public function get leftPeak():Number |
|---|
| 106 |
{ |
|---|
| 107 |
if ( _channel_flg ) |
|---|
| 108 |
return _channel.leftPeak; |
|---|
| 109 |
else |
|---|
| 110 |
return NaN; |
|---|
| 111 |
} |
|---|
| 112 |
|
|---|
| 113 |
/** |
|---|
| 114 |
* rightPeak |
|---|
| 115 |
*/ |
|---|
| 116 |
public function get rightPeak():Number |
|---|
| 117 |
{ |
|---|
| 118 |
if ( _channel_flg ) |
|---|
| 119 |
return _channel.rightPeak; |
|---|
| 120 |
else |
|---|
| 121 |
return NaN; |
|---|
| 122 |
} |
|---|
| 123 |
|
|---|
| 124 |
//---------------------------------------------------------------------------------------------- SoundTransform |
|---|
| 125 |
|
|---|
| 126 |
/** |
|---|
| 127 |
* pan |
|---|
| 128 |
*/ |
|---|
| 129 |
public function get pan():Number |
|---|
| 130 |
{ |
|---|
| 131 |
if ( _channel_flg ) |
|---|
| 132 |
return _channel.soundTransform.pan; |
|---|
| 133 |
else |
|---|
| 134 |
return NaN; |
|---|
| 135 |
} |
|---|
| 136 |
public function set pan( value:Number ):void |
|---|
| 137 |
{ |
|---|
| 138 |
if ( _channel_flg ) |
|---|
| 139 |
{ |
|---|
| 140 |
var st:SoundTransform = _channel.soundTransform; |
|---|
| 141 |
st.pan = value; |
|---|
| 142 |
_channel.soundTransform = st; |
|---|
| 143 |
} |
|---|
| 144 |
} |
|---|
| 145 |
|
|---|
| 146 |
/** |
|---|
| 147 |
* volume |
|---|
| 148 |
*/ |
|---|
| 149 |
public function get volume():Number |
|---|
| 150 |
{ |
|---|
| 151 |
if ( _channel_flg ) |
|---|
| 152 |
return _channel.soundTransform.volume; |
|---|
| 153 |
else |
|---|
| 154 |
return NaN; |
|---|
| 155 |
} |
|---|
| 156 |
public function set volume( value:Number ):void |
|---|
| 157 |
{ |
|---|
| 158 |
if ( _channel_flg ) |
|---|
| 159 |
{ |
|---|
| 160 |
var st:SoundTransform = _channel.soundTransform; |
|---|
| 161 |
st.volume = value; |
|---|
| 162 |
_channel.soundTransform = st; |
|---|
| 163 |
} |
|---|
| 164 |
} |
|---|
| 165 |
|
|---|
| 166 |
} |
|---|
| 167 |
|
|---|
| 168 |
} |
|---|