用flex制作简单的mp3播放器

编程入门 行业动态 更新时间:2024-10-28 12:28:20
以下是制作简单mp3播放器的核心代码。
<?xml version="1.0" encoding="utf-8"?>
<mx:Application 
    xmlns:mx="http://www.adobe/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>









本文转自 weijie@java 51CTO博客,原文链接:http://blog.51cto/weijie/66462,如需转载请自行联系原作者

更多推荐

用flex制作简单的mp3播放器

本文发布于:2023-06-14 00:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1418962.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:播放器   简单   flex

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!