| 1 |
/* |
|---|
| 2 |
* Copyright(c) 2006-2007 the Spark project. |
|---|
| 3 |
* |
|---|
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|---|
| 5 |
* you may not use this file except in compliance with the License. |
|---|
| 6 |
* You may obtain a copy of the License at |
|---|
| 7 |
* |
|---|
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|---|
| 9 |
* |
|---|
| 10 |
* Unless required by applicable law or agreed to in writing, software |
|---|
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|---|
| 12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
|---|
| 13 |
* either express or implied. See the License for the specific language |
|---|
| 14 |
* governing permissions and limitations under the License. |
|---|
| 15 |
*/ |
|---|
| 16 |
|
|---|
| 17 |
package org.libspark.utils |
|---|
| 18 |
{ |
|---|
| 19 |
import flash.media.Camera; |
|---|
| 20 |
import flash.media.Microphone; |
|---|
| 21 |
import flash.media.SoundLoaderContext; |
|---|
| 22 |
import flash.media.SoundMixer; |
|---|
| 23 |
import flash.media.SoundTransform; |
|---|
| 24 |
import flash.media.Video; |
|---|
| 25 |
import flash.media.Sound; |
|---|
| 26 |
import flash.media.SoundChannel; |
|---|
| 27 |
import flash.system.Security; |
|---|
| 28 |
import flash.system.SecurityPanel; |
|---|
| 29 |
import flash.net.URLRequest; |
|---|
| 30 |
import flash.utils.ByteArray; |
|---|
| 31 |
|
|---|
| 32 |
/** |
|---|
| 33 |
* flash.media パッケージのためのユーティリティクラスです |
|---|
| 34 |
*/ |
|---|
| 35 |
public class MediaUtil |
|---|
| 36 |
{ |
|---|
| 37 |
|
|---|
| 38 |
/** |
|---|
| 39 |
* マイクを取得します. |
|---|
| 40 |
* |
|---|
| 41 |
* @param index マイクのインデックス値です。 |
|---|
| 42 |
* @param showSettings セキュリティパネルのマイクの設定を表示の有無。 |
|---|
| 43 |
* @param loopBack マイクによってキャプチャされたオーディオをローカルスピーカーに転送するかどうかを指定します。 |
|---|
| 44 |
* @param useEchoSuppression オーディオコーデックのエコー抑制機能を使用するかどうかを指定します。 |
|---|
| 45 |
* @return オーディオをキャプチャする Microphone オブジェクトの参照を返します。 |
|---|
| 46 |
* @author michi at seyself.com |
|---|
| 47 |
*/ |
|---|
| 48 |
public static function getMicrophone(index:int=0, showSettings:Boolean = false, |
|---|
| 49 |
loopBack:Boolean=true, useEchoSuppression:Boolean=false):Microphone |
|---|
| 50 |
{ |
|---|
| 51 |
var mic:Microphone = Microphone.getMicrophone(index); |
|---|
| 52 |
if (mic) { |
|---|
| 53 |
if(showSettings) Security.showSettings(SecurityPanel.MICROPHONE); |
|---|
| 54 |
mic.setLoopBack(loopBack); |
|---|
| 55 |
mic.setUseEchoSuppression(useEchoSuppression); |
|---|
| 56 |
} |
|---|
| 57 |
return mic; |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
/** |
|---|
| 61 |
* ビデオをキャプチャする Camera オブジェクトへの参照を返します. |
|---|
| 62 |
* <br /> |
|---|
| 63 |
* 戻り値のオブジェクトには camera と video が含まれています。<br /> |
|---|
| 64 |
* camera : Camera クラスのインスタンスオブジェクト<br /> |
|---|
| 65 |
* video : Video クラスのインスタンスオブジェクト<br /> |
|---|
| 66 |
* |
|---|
| 67 |
* @param name 取得するカメラを names プロパティで返される配列から決定します。 |
|---|
| 68 |
* @return Camera オブジェクトと Video オブジェクトへの参照を保持するオブジェクト |
|---|
| 69 |
* @author michi at seyself.com |
|---|
| 70 |
*/ |
|---|
| 71 |
public static function getCamera(name:String=null):Object |
|---|
| 72 |
{ |
|---|
| 73 |
var camera:Camera = Camera.getCamera(name); |
|---|
| 74 |
var video:Video = new Video(camera.width, camera.height); |
|---|
| 75 |
video.attachCamera(camera); |
|---|
| 76 |
return { camera: camera, video: video }; |
|---|
| 77 |
} |
|---|
| 78 |
|
|---|
| 79 |
/** |
|---|
| 80 |
* 外部MP3ファイルを指定してサウンドを再生します. |
|---|
| 81 |
* <br /> |
|---|
| 82 |
* 戻り値のオブジェクトには sound と channel が含まれています。<br /> |
|---|
| 83 |
* sound : Sound クラスのインスタンスオブジェクト<br /> |
|---|
| 84 |
* channel : SoundChannel クラスのインスタンスオブジェクト<br /> |
|---|
| 85 |
* |
|---|
| 86 |
* @param url 外部の MP3 ファイルを指定する URL です。 |
|---|
| 87 |
* @param loops サウンドチャネルの再生が停止するまで startTime 値に戻ってサウンドの再生を繰り返す回数を定義します。 |
|---|
| 88 |
* @param sndTransform サウンドチャンネルに割り当てられた初期 SoundTransform オブジェクトです。 |
|---|
| 89 |
* @param bufferTime サウンドのストリーミングを開始するまでに、バッファにストリーミングサウンドをプリロードする秒数です。 |
|---|
| 90 |
* @param checkPolicyFile サウンドのロードを開始する前に、Flash Player が、ロードされるサウンドのサーバーからのクロスドメインポリシーファイルのダウンロードを試行するかどうかを指定します。 |
|---|
| 91 |
* @return Sound オブジェクトと SoundChannel オブジェクトへの参照を保持するオブジェクト |
|---|
| 92 |
* @author michi at seyself.com |
|---|
| 93 |
*/ |
|---|
| 94 |
public static function playSound(url:String, loops:uint = 0, sndTransform:SoundTransform = null, |
|---|
| 95 |
bufferTime:Number = 1000, checkPolicyFile:Boolean = false):Object |
|---|
| 96 |
{ |
|---|
| 97 |
var sound:Sound = new Sound(); |
|---|
| 98 |
var context:SoundLoaderContext = new SoundLoaderContext(bufferTime, checkPolicyFile); |
|---|
| 99 |
sound.load( new URLRequest(url), context ); |
|---|
| 100 |
var channel:SoundChannel = sound.play( 0, loops, sndTransform ); |
|---|
| 101 |
return { sound: sound, channel: channel }; |
|---|
| 102 |
} |
|---|
| 103 |
|
|---|
| 104 |
/** |
|---|
| 105 |
* 現在のサウンド波形からのスナップショットを ByteArray オブジェクトに配置した状態で取得します. |
|---|
| 106 |
* |
|---|
| 107 |
* @param FFTMode サウンドデータに対して最初にフーリエ変換を実行するかどうかを示すブール値です。 |
|---|
| 108 |
* @param stretchFactor サウンドサンプリングの解像度です。 |
|---|
| 109 |
* @return 現在のサウンド波形からのスナップショットを配置した ByteArray オブジェクト。 |
|---|
| 110 |
* @author michi at seyself.com |
|---|
| 111 |
*/ |
|---|
| 112 |
public static function computeSpectrum(FFTMode:Boolean=false, stretchFactor:int=0):ByteArray |
|---|
| 113 |
{ |
|---|
| 114 |
SoundMixer.computeSpectrum( soundData, FFTMode, stretchFactor); |
|---|
| 115 |
return soundData; |
|---|
| 116 |
} |
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
private static var soundData:ByteArray = new ByteArray(); |
|---|
| 120 |
|
|---|
| 121 |
} |
|---|
| 122 |
|
|---|
| 123 |
} |
|---|