博客中 Flex4/Flash mp3音乐播放器实例 含演示地址
要求
播放器演示已经在博客banner部分给出了,下面还是上一截图吧:
下面是程序的核心业务代码:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="330" height="75" backgroundAlpha="1.0" backgroundColor="#9C4B4B"
preloaderChromeColor="#060606"
creationComplete="initApp()">
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert; /**
* musicItem Object 音乐信息对象
*/
[Bindable]
public var musicItem:Object; /**
* 音乐是否正在播放
*/
private var isplaying:Boolean = false; /**
* 播放器音量
*/
private var currentVolum:Number =0.5;
/**
* 正在播放的音乐的URL字符串
* 从主程序中获得 player.currentMusicUrlString=musicSource;
*/
public var currentMusicUrlString:String;
/**
* 正在播放的音乐的URLRequest
*/
private var currentMusicUrlRequest:URLRequest;
/**
* 正在播放的音乐的Sound
*/
private var currentMusicSound:Sound;
/**
* 正在播放的音乐的SoungChannel
* SoundChannel 类控制应用程序中的声音。每个声音均分配给一个声道,而且应用程序可以具有混合在一起的多个声道。SoundChannel 类包含 stop() 方法、用于监控声道幅度(音量)的属性以及用于对声道指定 SoundTransform 对象的属性。
*/
private var currentMusicChannel:SoundChannel;
/**
* 正在播放的音乐的 SoundTransform
* SoundTransform 类包含音量和平移的属性。
*/
private var currentMusicTransform:SoundTransform; /**
* 正在播放的音乐的总时间
*/
private var currentMusicTotleTime:Number =0;
/**
* 正在播放的音乐的播放进度参数
*/
private var currentMusicPosition:int =0; private var songs:ArrayCollection=new ArrayCollection([
{name:"初恋",singer:"张力尹",pic:"data/images/zly.jpg",uri:"data/chulian.mp3"},
{name:"纯真的爱",singer:"张力尹",pic:"data/images/zly.jpg",uri:"data/chunzhendeai.mp3"},
{name:"相信爱",singer:"张力尹",pic:"data/images/zly.jpg",uri:"data/xiangxinai.mp3"},
{name:"星愿(I WILL)",singer:"张力尹",pic:"data/images/zly.jpg",uri:"data/I will.mp3"},
{name:"TIMELESS",singer:"张力尹",pic:"data/images/zly.jpg",uri:"data/TIMELESS.mp3"},
{name:"BLUE",singer:"BigBang",pic:"data/images/ALIVE-BIGBANG.jpg",uri:"data/BigBang - BLUE.mp3"},
{name:"BLUE(指弹)",singer:"Gabriella Quevedo",pic:"data/images/ALIVE-BIGBANG.jpg",uri:"data/Gabriella Quevedo - blue.mp3"},
{name:"You're Beautiful",singer:"James Blunt",pic:"data/images/s1461123.jpg",uri:"data/You're Beautiful.mp3"},
{name:"Only Friends",singer:"Rita Calypso",pic:"data/images/s3786226.jpg",uri:"data/Only Friends.mp3"},
{name:"총맞은것처럼(像中枪一样)",singer:"白智英",pic:"data/images/s3387692.jpg",uri:"data/Muz Cast - xiangzhongqiangyiyang.mp3"},
{name:"是否",singer:"G.E.M",pic:"data/images/150_albumpic_444525_0[1].jpg",uri:"data/G.E.M. - shifou.mp3"},
{name:"Young Girls",singer:"Bruno Mars",pic:"data/images/Bruno Mars.jpg",uri:"data/Bruno Mars - Young Girls.mp3"},
{name:"Nothing On You",singer:"B.O.B&Bruno Mars",pic:"data/images/Bruno Mars.jpg",uri:"data/B.o.B. - Nothing On You.mp3"},
{name:"Young Girls(指弹)",singer:"Gabriella Quevedo",pic:"data/images/Bruno Mars.jpg",uri:"data/Gabriella Quevedo-Young Girls.mp3"},
{name:"Im Yours(指弹)",singer:"Gabriella Quevedo",pic:"data/images/Bruno Mars.jpg",uri:"data/Im Yours -Gabriella Quevedo.mp3"},
{name:"金泰妍 - 가까이(靠近)",singer:"金泰妍 ",pic:"data/images/jintaiyan.jpg",uri:"data/closer.mp3"},
{name:"Grace",singer:"李秀英 ",pic:"data/images/s2868209.jpg",uri:"data/Grace.mp3"},
{name:"Twenty Nine",singer:"李秀英 ",pic:"data/images/s2722298.jpg",uri:"data/Twenty Nine.mp3"} ]); /**
* 随机获取一首歌曲
*/
private function getMusicItem():Object{
var index: Number = Math.round(Math.random()*(songs.length-1)); //产生一个随机数
musicItem=songs[index];
return musicItem;
} /**
* 程序初始化
*/
private function initApp():void{
//初始话一条数据
getMusicItem();
//UI控件事件监听
playAndPause.addEventListener(MouseEvent.CLICK,musicPlay); //播放按钮
next.addEventListener(MouseEvent.CLICK,autoPlayNext);
playingProcess.addEventListener(Event.CHANGE,playingProcess_changeHandler); //进度条滚动事件
} private function musicPlay(event:MouseEvent):void{
if(!isplaying){ //播放 false
//此状态为 启动播放器 然后点击播放按钮 状态(空状态)
if(currentMusicSound==null&¤tMusicChannel ==null){
currentMusicUrlString=musicItem.uri;
currentMusicUrlRequest =new URLRequest(currentMusicUrlString);
currentMusicSound = new Sound();
currentMusicSound.load(currentMusicUrlRequest);
currentMusicSound.addEventListener(Event.COMPLETE,load_CompleteHandler);
currentMusicChannel = currentMusicSound.play();//开始播放
timer_GetCurrentPositionHandler();//同步更新已经播放的时间的计时器
}else{//此状态为 暂停后点击播放按钮 状态
currentMusicChannel = currentMusicSound.play(currentMusicPosition);
}
isplaying=true;
}else{ //暂停
//此状态为 播放过程中点击 暂停按钮 状态
currentMusicPosition = currentMusicChannel.position;//记录暂停位置
currentMusicChannel.stop();//暂停
isplaying=false;
} //currentMusicChannel.addEventListener(Event.SOUND_COMPLETE,autoPlayNext);//自动播放下一首 } /**
* 自动播放下一首 和 next按钮采用同样的方式吧
* @param event
*
*/
protected function autoPlayNext(event:Event):void{//过滤参数问题
getMusicItem();
if(currentMusicSound!=null&¤tMusicChannel!=null){
currentMusicChannel.stop();//暂停
}
clearPar();
currentMusicUrlString=musicItem.uri;
currentMusicUrlRequest =new URLRequest(currentMusicUrlString);
currentMusicSound = new Sound();
currentMusicSound.load(currentMusicUrlRequest);
currentMusicSound.addEventListener(Event.COMPLETE,load_CompleteHandler);
playAndPause.selected=true;
isplaying =true;
currentMusicChannel = currentMusicSound.play();//开始播放
timer_GetCurrentPositionHandler();//同步更新已经播放的时间的计时器
currentMusicChannel.addEventListener(Event.SOUND_COMPLETE,autoPlayNext);//自动播放下一首 } /**
* 正在播放的歌曲的总时长
*/
private var len:int; /**
* 文件加载完成 能读取到音乐的总时长
* @param event
*
*/
protected function load_CompleteHandler(event:Event):void{ len = currentMusicSound.length; } /**
* 同步更新已经播放的时间的计时器
*
*/
protected function timer_GetCurrentPositionHandler():void{
var clock:Timer = new Timer(100,int(len/1000/60*10));//每0.1秒更新一次
clock.start();
clock.addEventListener(TimerEvent.TIMER,showTime);
} /**
* 显示已经播放的总时间
* @param event
*
*/
protected function showTime(event:Event):void{
playingProcess.maximum = int(len/1000)*10;//最大值
playingProcess.value = int(currentMusicPosition/1000*10); //当前值
currentMusicPosition = currentMusicChannel.position; } /**
* 播放进度条 可以拖动
* @param event
*
*/
protected function playingProcess_changeHandler(event:Event):void{
if(currentMusicChannel!=null){
currentMusicPosition = playingProcess.value*1000/10;//当前音乐播放进度
currentMusicChannel.stop();
currentMusicChannel = currentMusicSound.play(currentMusicPosition);
isplaying=true; playAndPause.selected=true;
currentMusicChannel.addEventListener(Event.SOUND_COMPLETE,autoPlayNext);//自动播放下一首 }else{ playingProcess.value=0;
}
} /**
* 清除参数
* currentMusicSound = null;
* currentMusicChannel = null;
* currentMusicPosition = 0;
*
*/
private function clearPar():void{
currentMusicSound = null;
currentMusicChannel = null;
currentMusicPosition = 0;
} ]]>
</fx:Script>
<s:Group verticalCenter="0" >
<!--背景-->
<s:Rect width="330" height="75">
<s:fill>
<s:SolidColor color="#FFFFFF"/>
</s:fill>
</s:Rect>
<s:BitmapImage source="{musicItem.pic}" smooth="true" width="75" height="75" />
<s:VGroup left="85" top="10" right="10" bottom="0" gap="0">
<s:HGroup height="45" width="235" verticalAlign="middle" >
<s:VGroup height="45" gap="0" width="150">
<!--歌名-->
<s:Label maxDisplayedLines="1" width="100%" height="25" fontFamily="微软雅黑" fontSize="14"
fontWeight="bold" text="{musicItem.name}" verticalAlign="middle"/>
<!--歌手-->
<s:Label maxDisplayedLines="1" width="100%" height="20" fontFamily="微软雅黑" text="{musicItem.singer}"
verticalAlign="middle"/>
</s:VGroup>
<s:HGroup width="100%" horizontalAlign="right" gap="30" paddingRight="5">
<!--next-->
<s:Button id="next" skinClass="components._ButtonSkin1"/>
<!--play-->
<s:ToggleButton id="playAndPause" skinClass="components.pToggleButtonSkin1"/>
</s:HGroup>
</s:HGroup>
<s:Group width="100%" height="20">
<!--进度条-->
<s:ScrubBar id="playingProcess" horizontalCenter="0" verticalCenter="-2" skinClass="skinks.playercontrol.scrubbar.ScrubBar"/>
</s:Group>
</s:VGroup>
</s:Group> </s:Application>
博客中 Flex4/Flash mp3音乐播放器实例 含演示地址的更多相关文章
- 推荐美丽的flash网页MP3音乐播放器
文章来源:PHP开发学习门户 地址:http://www.phpthinking.com/archives/491 在网页制作中.假设想在网页中插入mp3音乐来增添网页的互动感,提升用户体验度,这个时 ...
- 吴裕雄--天生自然python学习笔记:python 用pygame模块制作 MP3 音乐播放器
利用 music 对象来制作一个 MP3 音乐播放器 . 应用程序总览 从歌曲清单中选择指定的歌曲,单击“播放”按钮可开始播放, 在播放 xxx 歌曲”的信息. 歌曲播放的过程中,可以暂停.停止,也可 ...
- Flex4/Flash开发在线音乐播放器 , 含演示地址
要求 必备知识 本文要求基本了解 Adobe Flex编程知识和JAVA基础知识. 开发环境 MyEclipse10/Flash Builder4.6/Flash Player11及以上 演示地址 演 ...
- ES6 class——音乐播放器实例
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- Android应用开发--MP3音乐播放器代码实现(一)
需求1:将内存卡中的MP3音乐读取出来并显示到列表当中 1. 从数据库中查询所有音乐数据,保存到List集合当中,List当中存放的是Mp3Info对象 2. 迭代List集合,把每一个Mp3 ...
- jquery+jplayer实现歌词同步的mp3音乐播放器效果
实例预览 下载地址 实例代码 <div class="container"> <div class="demo"> <textar ...
- 痞子衡嵌入式:基于恩智浦i.MXRT1010的MP3音乐播放器(RT-Mp3Player)设计
大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是基于i.MXRT1011的MP3播放器参考设计. i.MXRT1011是恩智浦i.MXRT四位数系列的入门型号,虽然是入门级,可也是50 ...
- Android开发实战之简单音乐播放器
最近开始学习音频相关.所以,很想自己做一个音乐播放器,于是,花了一天学习,将播放器的基本功能实现了出来.我觉得学习知识点还是蛮多的,所以写篇博客总结一下关于一个音乐播放器实现的逻辑.希望这篇博文对你的 ...
- 在个人博客中优雅的使用Gitalk评论插件
在上一篇博客<程序员如何从0到1搭建自己的技术博客>中,我们了解了如何快速的从0到1搭建一个个人博客. 其实细心的你会发现,该博客用到了一个评论插件,这个插件就是Gitalk. 如果想要在 ...
随机推荐
- Js闭包函数
一.变量的作用域要理解闭包,首先必须理解Javascript特殊的变量作用域.变量的作用域无非就是两种:全局变量和局部变量.Javascript语言的特殊之处,就在于函数内部可以直接读取全局变量. ( ...
- spring+springMVC+mybatis的框架项目基础环境搭建
上一个项目在后台用到spring+springMVC+mybatis的框架,先新项目初步需求也已经下来,不出意外的话,应该也是用这个框架组合. 虽然在之前activiti相关的学习中所用到的框架也是这 ...
- 使用mongo-java-driver3.0.2.jar和mongodb3.0在java代码中的用户验证4
以下是使用mongo-java-driver3.0.2.jar和mongodb3.0.4在java代码中的用户验证: ServerAddress sa = new ServerAddress(host ...
- 关于Linux中exec的一点心得
最近在学习linux操作系统中的相关知识,在使用execlp系统调用时,发现了些有趣的东西. 首先,关于execlp函数的用法: int execlp(const char *file, const ...
- PO_PO系列 - 收货管理分析(案例)
2014-07-01 Created By BaoXinjian
- NeHe OpenGL教程 第三十七课:卡通映射
转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...
- C#(二维数组/集合)
一.二维数组int [,] array = new int[5,3];//有五个一维数组,每一个一维数组有3个元素 /打印出来一个“王”这个字string[,] wang = new string[, ...
- 在eclipse中下载包含子模块(Submodules)的git项目
先将项目下载下来 , 这时由于是子项目的原因 , 下载的项目中不包含任何子项目 . 这时在eclipse的Git Repositories中 , 选中Submodules , 右键点击update即可 ...
- JavaScript笔记之数组 keyword(存储和释放&堆栈 & 按值 引用)
1.数组创建及初始化 var obj=new Array(); var arr=[]; 可以延伸为长度一定的,字面量定义数组 2.堆栈 按值传递 引用类型 数组是引用类型,不是值传递, 栈:系桶自动分 ...
- Coding.net 代码管理快速入门
当项目创建好了之后,我们该如何上传代码到 coding 上呢? Coding 网站使用“ Git 仓库”(类似 github )来管理代码. 其操作原理在于:利用 git 服务,将本地的项目目录下的文 ...