zoukankan      html  css  js  c++  java
  • Mp3播放器频谱——官方帮助文档

    import flash.display.Sprite;
    import flash.display.Graphics;
    import flash.events.Event;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.media.SoundMixer;
    import flash.net.URLRequest;
    import flash.utils.ByteArray;
    import flash.text.TextField;
    
    
    SoundMixer_computeSpectrumExample();
    
    function SoundMixer_computeSpectrumExample() {
    	var snd:Sound = new Sound();
    	var req:URLRequest=new URLRequest("喜剧之王.mp3");
    	snd.load(req);
    
    	var channel:SoundChannel;
    	channel=snd.play();
    	addEventListener(Event.ENTER_FRAME, onEnterFrame);
    	channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
    }
    
    function onEnterFrame(event:Event):void {
    	var bytes:ByteArray = new ByteArray();
    	const PLOT_HEIGHT:int=200;
    	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();
    }
    
    function onPlaybackComplete(event:Event):void {
    	removeEventListener(Event.ENTER_FRAME, onEnterFrame);
    }
    

  • 相关阅读:
    移位运算符<<与>>
    在线颜色选择器
    CSS鼠标指针cursor样式
    JavaScript实现自定义右键菜单
    如何去掉ul和li前面的小黑点
    转载:利用本地存储实现记录滚动条的位置
    CSS中样式覆盖优先顺序
    断言类
    MQ发送定时消息
    看代码所学3
  • 原文地址:https://www.cnblogs.com/leon3286/p/1792545.html
Copyright © 2011-2022 走看看