注册 | 登录 忘记密码? 51cto首页 | 博客 | 论坛 | 招聘
热点文章 模拟Linux客户端远程登陆L..
 帮助

用flex制作简单的mp3播放器


2008-03-18 12:44:45
 标签:flex 开发 编程   [推送到技术圈]

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://weijie.blog.51cto.com/340746/66462
以下是制作简单mp3播放器的核心代码。
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
    xmlns:mx="http://www.adobe.com/2006/mxml"
    width="400" height="110" layout="vertical"
    horizontalAlign="center" verticalAlign="center"
>
    <mx:Script>
        <![CDATA[
            import mx.core.SoundAsset;
            import flash.media.*;

            [Embed(source="song.mp3")]
            [Bindable]
            public var Song:Class;
            public var mySong:SoundAsset = new Song() as SoundAsset;
            public var channel:SoundChannel;
           
            public function playSound():void
            {
                // 先 停止
                stopSound();
               
                // 在播放
                channel = mySong.play(0,int.MAX_VALUE);
            }
           
            public function stopSound():void
            {
                // 停止
                if ( channel != null ) channel.stop();
            }
        ]]>
    </mx:Script>
    <mx:HBox>
        <mx:Button label="play" click="playSound();"/>
        <mx:Button label="stop" click="stopSound();"/>       
    </mx:HBox>
</mx:Application>

本文出自 “魏杰的技术专栏” 博客,请务必保留此出处http://weijie.blog.51cto.com/340746/66462





    文章评论
 
2008-05-06 22:22:43
可以留个联系方式么?我的MSN:zhiming-84@hotmail.com
好向你学习学习,,呵呵。

2008-08-12 10:20:07
public function playSound():void
        {
          // 先 停止
          stopSound();
         
          // 在播放
          channel = mySong.play(0,int.MAX_VALUE);
        }

中间如果再放入一个playbutton的visable就好了

 

发表评论

昵   称:
验证码:  点击图片可刷新验证码  博客过2级,无需填写验证码
内   容: