Public Class Main Extends Sprite
{
Private VaR URL: String = "Musicloud ";
Private VaR Sound: Sound = new sound (); // Create sound
Private VaR Schannel: soundchannel; // Create sound Channel
Private VaR Barray: bytearray = new bytearray (); // Create byte array
Private VaR Ary: array;
Private VaR N: Number = 0; // Number of records
Public Function Main (): void
{
Init ();
}
Private Function Init (): void
{
// Load the MP3 file to the sound and play it back
VaR Req: URLRequest = new URLRequest (URL );
Sound. Load (req );
Sound. Play ();
// Events that are repeatedly triggered from the first frame of loading
This. addeventlistener (event. enter_frame, show );
}
// Start plotting
Private Function Show (EVT: Event): void
{
N = 0; // First cleared
This. Graphics. Clear (); // Clear all images
// Convert audio data into byte arrays and save them in barray. Then, a small vertical line with dynamic changes will be generated.
Soundmixer. computespectrum (barray, True , 0 );
// Draw a dynamic small vertical line animation, so that each line is separated by a distance, so I + = 16
For ( VaR I: uint = 0; I <100; I + = 5)
{
N = barray. readfloat ();
VaR Num: Number = N * 100;
This. Graphics. linestyle (3, 0x00ff00 );
This. Graphics. moveTo (I, 100 ); // Line start point
This. Graphics. lineto (I, 100-num ); // Draw line endpoint
This. Graphics. endfill ();
}
}
}
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.