Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (537.93 KB, 14 trang )
<span class='text_page_counter'>(1)</span><div class='page_container' data-page=1>
( tất nhiên phải có dịng lệnh : import flash.media.Sound;)
soundFile = new URLRequest("song.mp3");
_sound.load(soundFile);
_sound.load(new URLRequest("song.mp3"));
import flash.display.Sprite;
import flash.media.Sound;
import flash.net.URLRequest;
public class LoadSoundExample extends Sprite {
private var _sound:Sound;
public function LoadSoundExample ( ) {
_sound = new Sound( );
_sound.load(new URLRequest("song.mp3"));
}
}
}
var request:URLRequest = new URLRequest("song.mp3");
var buffer:SoundLoaderContext = new SoundLoaderContext(5000);
_sound = new Sound(request, buffer);
_sound.play( );
var request:URLRequest = new URLRequest("song.mp3");
var buffer:SoundLoaderContext = new SoundLoaderContext(5000);
_sound = new Sound( );
_sound.load(request, buffer);
_sound.play( );
package {
import flash.display.Sprite;
import flash.media.Sound;
import flash.net.URLRequest;
public class CuePoints extends Sprite {
private var _sound:Sound;
private var _cuePoints:Array;
public function CuePoints( ) {
_cuePoints = [0, 10000, 30000, 68000, 120000];
_sound = new Sound(new URLRequest("song.mp3"));
// Play from the third cuepoint (30 seconds in)
playCuePoint(2);
}
public function playCuePoint(index:int):void {
_sound.play(_cuePoints[index]);
}
}
}
package {
import flash.net.URLRequest;
import flash.events.Event;
public class ProgressBar extends Sprite {
private var _sound:Sound;
public function ProgressBar( ) {
addEventListener(Event.ENTER_FRAME, onEnterFrame);
_sound = new Sound(new URLRequest("song.mp3"));
_sound.play( );
}
public function onEnterFrame(event:Event):void
{
var barWidth:int = 200;
var barHeight:int = 5;
var loaded:int = _sound.bytesLoaded;
var total:int = _sound.bytesTotal;
if(total > 0) {
// Draw a background bar
graphics.beginFill(0xFFFFFF);
graphics.drawRect(10, 10, barWidth, barHeight);
graphics.endFill( );
// The percent of the sound that has loaded
var percent:Number = loaded / total;
// Draw a bar that represents the percent of
// the sound that has loaded
graphics.beginFill(0xCCCCCC);
graphics.drawRect(10, 10,
barWidth * percent, barHeight);
graphics.endFill( );
}
}
}
}
public class ProgressBar1 extends Sprite {
private var _sound:Sound;
public function ProgressBar1( ) {
addEventListener(Event.ENTER_FRAME, onEnterFrame);
_sound = new Sound(new
URLRequest(" />8b6130/f/08/f086b23ff9770c5dc0f7304825226155.mp3?filename=Mua-Va-Em-Bang-Kieu.mp3"));
_sound.play( );
public function onEnterFrame(event:Event):void
{
var barWidth:int = 200;
var barHeight:int = 5;
var loaded:int = _sound.bytesLoaded;
var total:int = _sound.bytesTotal;
if(total > 0) {
// Draw a background bar
graphics.beginFill(0xFffFFF);
graphics.drawRect(10, 10, barWidth, barHeight);
graphics.endFill( );
// The percent of the sound that has loaded
var percent:Number = loaded / total;
// Draw a bar that represents the percent of
// the sound that has loaded
graphics.beginFill(0xC12111);
graphics.drawRect(10, 10,
barWidth * percent, barHeight);
graphics.endFill( );
t1.text=(Math.round(100*percent)).toString()+"%" ;
}
}
}
}
• artist
import flash.display.Sprite;
import flash.media.Sound;
import flash.net.URLRequest;
import flash.events.Event;
import flash.text.*;
public class ID3Reader extends Sprite {
private var _sound:Sound;
public function ID3Reader ( ) {
_sound = new Sound(new URLRequest("song.mp3"));
_sound.addEventListener(Event.ID3, onID3);
_sound.play( );
}
public function onID3(event:Event):void {
// Create a text field and display it
var id3Display:TextField = new TextField( );
id3Display.backgroundColor=0xC7F755;
addChild(id3Display);
id3Display.x = 10;
id3Display.y = 20;
id3Display.width = 200;
id3Display.height = 200;
id3Display.background = true;
id3Display.multiline = true;
id3Display.wordWrap = true;
// Add some info about the song to the text field
id3Display.text += " ten bai hat : "+_sound.id3.songName + "\n";
id3Display.text += " ten ca si : "+_sound.id3.artist + "\n";
id3Display.text += " Album : "+_sound.id3.album + "\n";
id3Display.text += "Nam san xuat : "+_sound.id3.year + "\n"; }
}
}
package {
import flash.display.Sprite;
import flash.media.Sound;
import flash.net.URLRequest;
import flash.events.Event;
import flash.media.SoundChannel;
public class PlayList extends Sprite {
private var _sound:Sound;
private var _channel:SoundChannel;
private var _playList:Array; // mảng chứa danh sách nhạc
private var _index:int = 0; // bài nhạc hiện tại
public function PlayList( ) {
// tạo danh sách nhạc
_playList = ["song1.mp3",
"song2.mp3",
"song3.mp3"];
playNextSong( );
}
private function playNextSong( ):void
{
// If there are still songs in the playlist
if(_index < _playList.length) {
// Tạo bài nhạc , load và chơi bài đó
// _playList[_index] chứa tên và ñường dẫn của bài hát tiếp theo
_sound = new Sound( );
// Thêm listener vào channel
_channel.addEventListener(Event.SOUND_COMPLETE,
onComplete);
// tăng biến ñếm lên 1 ñơn vị ñể ñược bài tiếp theo
_index++;
}
}
public function onComplete(event:Event):void
{
playNextSong( );
}
}
}
package {
import flash.display.Sprite;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;
import flash.events.Event;
import flash.display.Sprite;
import flash.events.MouseEvent;
public class PlayPause extends Sprite {
private var _sound:Sound;
private var _channel:SoundChannel;
private var _playPauseButton:Sprite;
private var _playing:Boolean = false;
private var _position:int;
public function PlayPause( ) {
// tạo một sound và load file âm thanh rồi chạy file đó
_sound = new Sound(new URLRequest("song.mp3"));
_channel = _sound.play( );
_playing = true;
// Tạo một Sprite ñể dùng button
_playPauseButton = new Sprite( );
addChild(_playPauseButton);
_playPauseButton.x = 10;
_playPauseButton.y = 20;
_playPauseButton.graphics.beginFill(0xffcccc);
_playPauseButton.graphics.drawRoundRect(0, 0, 20, 40,10);
_playPauseButton.addEventListener(MouseEvent.MOUSE_UP,
onPlayPause);
}
// Nếu đang chạy thì dừng lại và ghi nhớ vị trí dừng
if(_playing) {
_position = _channel.position;
_channel.stop( );
}
// Nếu dừng thì restart
_channel = _sound.play(_position);
}
_playing = !_playing;
}
}
}
package {
import flash.display.Sprite;
import flash.media.Sound;
public class SoundLevels extends Sprite {
private var _sound:Sound;
private var _channel:SoundChannel;
public function SoundLevels( ) {
addEventListener(Event.ENTER_FRAME, onEnterFrame);
_sound = new Sound(new URLRequest("song.mp3"));
_channel = _sound.play( );
}
public function onEnterFrame(event:Event):void
{
var leftLevel:Number = _channel.leftPeak * 100;
var rightLevel:Number = _channel.rightPeak * 100;
graphics.clear( );
graphics.beginFill(0xcccccc);
graphics.drawRect(10, 10, leftLevel, 10);
graphics.endFill( );
graphics.beginFill(0xcccccc);
graphics.drawRect(10, 25, rightLevel, 10);
graphics.endFill( );
}
}
package {
import flash.display.Sprite;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.MouseEvent;
public class SoundLevels extends Sprite {
private var _sound:Sound;
private var _channel:SoundChannel;
private var _playing:Boolean = true;
private var _position:int;
private var _playPauseButton = new Sprite( );
public function SoundLevels( ) {
addEventListener(Event.ENTER_FRAME, onEnterFrame);
_sound = new Sound(new URLRequest("song.mp3"));
_channel = _sound.play( );
_playPauseButton = new Sprite( );
addChild(_playPauseButton);
_playPauseButton.x = 10;
_playPauseButton.y = 20;
_playPauseButton.graphics.beginFill(0xffcccc);
_playPauseButton.graphics.drawRect(0, 0, 20, 20);
_playPauseButton.addEventListener(MouseEvent.MOUSE_UP,onPlayPause);
}
public function onEnterFrame(event:Event):void
{
var leftLevel:Number = _channel.leftPeak * 100;
var rightLevel:Number = _channel.rightPeak * 100;
graphics.clear( );
graphics.beginFill(0xcccccc);
graphics.drawRect(10, 200, 10,-leftLevel);
graphics.endFill( );
graphics.beginFill(0xcccccc);
graphics.drawRect(30, 200, 10,-rightLevel);
graphics.endFill( );
graphics.beginFill(0xcccccc);
graphics.drawRect(50, 200, 10,-leftLevel-20*Math.random());
graphics.endFill( );
graphics.beginFill(0xcccccc);
graphics.drawRect(70, 200, 10,-leftLevel-20*Math.random());
graphics.endFill( );
graphics.beginFill(0xcccccc);
graphics.drawRect(90, 200, 10,-leftLevel-20*Math.random());
graphics.endFill( );
}
public function onPlayPause(event:MouseEvent):void {
// If playing, stop. Take note of position
if(_playing) {
_position = _channel.position;
_channel.stop( );
else {
// If not playing, re-start it at
// last known position
_channel = _sound.play(_position);
}
_playing = !_playing;
}
}
}
public function stopSounds(event:Event):void {
SoundMixer.stopAll( );
}
flash.media.Sound;flash.media.SoundChannel;flash.media.SoundMixer;flash.utils.ByteArray
;
import flash.media.SoundChannel;
import flash.media.SoundMixer;
import flash.net.URLRequest;
import flash.utils.ByteArray;
import flash.text.TextField;
public class SoundMixer_computeSpectrumExample extends Sprite {
public function SoundMixer_computeSpectrumExample() {
var snd:Sound = new Sound();
var req:URLRequest = new URLRequest("song.mp3");
snd.load(req);
var channel:SoundChannel;
channel = snd.play();
addEventListener(Event.ENTER_FRAME, onEnterFrame);
channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
}
private function onEnterFrame(event:Event):void {
var bytes:ByteArray = new ByteArray();
const PLOT_HEIGHT:int = 350;
const CHANNEL_LENGTH:int = 256;
SoundMixer.computeSpectrum(bytes, false, 0);
var g:Graphics = this.graphics;
g.clear();
g.lineStyle(0, 0x6600CC);
g.beginFill(0x6600CC);
g.moveTo(0, PLOT_HEIGHT);
var n:Number = 0;
for (var i:int = 0; i < CHANNEL_LENGTH; i++) {
n = (bytes.readFloat() * PLOT_HEIGHT);
g.lineTo(i * 2, PLOT_HEIGHT - n);
}
g.lineTo(CHANNEL_LENGTH * 2, PLOT_HEIGHT);
g.endFill();
g.lineStyle(0, 0xCC0066);
g.beginFill(0xCC0066, 0.5);
g.moveTo(CHANNEL_LENGTH * 2, PLOT_HEIGHT);
for (i = CHANNEL_LENGTH; i > 0; i--) {
n = (bytes.readFloat() * PLOT_HEIGHT);
g.lineTo(i * 2, PLOT_HEIGHT - n);
}
g.lineTo(0, PLOT_HEIGHT);
g.endFill();
}
private function onPlaybackComplete(event:Event):void {
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
}
}
}
import flash.display.Sprite;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundMixer;
import flash.net.URLRequest;
var _sound:Sound = new Sound(new URLRequest("song.mp3"));
var channel:SoundChannel = _sound.play( );
var transform1:SoundTransform = new SoundTransform();
transform1.volume = 0.8;
transform1.pan = -1.0;
channel.soundTransform = transform1;