Onelong

分享知识,与你一起进步......
RSS icon Home icon
  • 简单的android音乐播放器

    post by onelong / 2010-9-3 3:24 Friday [android]

    废话不说了!!最近做了个播放器,感觉有点问题,就是stop()和pause()函数的问题,stop()调用后音乐应该重头开始的!但是感觉他和pause()没有多大的分别!!是不是我那个地方写错了呢?

    看看源码吧!!

    //main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <L...

    阅读全文>>

    附件下载:
    MyPlayer.rar 12.52KB

  • ActionScript3实现一个简单mp3播放器

    post by onelong / 2010-4-14 23:30 Wednesday [MXML/ActionScript3.0]

    使用ActionScript3做一个播放器是一个相当容易的事情!看看adobe帮助的入门例子;播放音乐使用了Sound类,控制声音使用SoundChannel类,控制声音大小声道等使用SoundTransform类
    下面看看例子啦!
    package {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;

    public class Test extends Sprite {
    private var snd:Sound = new Sound();
    private var channel:SoundChannel = new SoundChannel();
    private var button:TextField = new TextField();
    private var stopbtn:TextField = new TextField();
    private var sprite:Sprite=new Sprite();
    private var pausePosition:Number=0;

    public function Test() {
    init();
    }
    private function init():void{
    var req:URLRequest = new URLRequest("22.mp3");//声音文件的地址....
    snd.load(req);

    button.x = 10;
    button.y = 10;
    button.text = "PLAY";
    button.border = true;
    button.background = true;
    button.selectable = false;
    button.autoSize = TextFieldAutoSize.CENTER;
    button.addEventListener(MouseEvent.CLICK, clickHandler);

    this.addChild(button);

    stopbtn.x = 60;
    stopbtn.y = 10;
    stopbtn.text = "STOP";
    stopbtn.border = true;
    stopbtn.background = true;
    stopbtn.selectable = false;
    stopbtn.autoSize = TextFieldAutoSize.CENTER;
    stopbtn.addEventListener(MouseEvent.CLICK, stophandle);

    this.addChild(stopbtn);

    sprite.graphics.beginFill(0);
    sprite.graphics.drawRect(10,30,100,4);
    sprite.graphics.endFill();
    sprite.scaleX=0;
    this.addChild(sprite);

    this.addEventListener(Event.ENTER_FRAME,onEnterFrame);
    }
    private function clickHandler(e:MouseEvent):void {
    if(button.text == "PLAY") {
    channel = snd.play(pausePosition);
    pausePosition = channel.position;
    channel.addEventListener(Event.SOUND_COMPLETE,soundCompele);
    this.addEventListener(Event.ENTER_FRAME,onEnterFrame);
    button.text = "PAUSE";
    }
    else {
    pausePosition = channel.position;
    channel.stop();
    button.text = "PLAY";
    this.removeEventListener(Event.ENTER_FRAME,onEnterFrame);
    }
    }
    private function stophandle(e:MouseEvent):void {
    channel.stop();
    pausePosition = 0;
    button.text = "PLAY";
    this.removeEventListener(Event.ENTER_FRAME,onEnterFrame);
    sprite.scaleX=0;
    }
    private function soundCompele(e:Event):void {
    channel.stop();
    pausePosition = 0;
    button.text = "PLAY";
    this.removeEventListener(Event.ENTER_FRAME,onEnterFrame);
    sprite.scaleX=0;
    }
    private function onEnterFrame(e:Event):void {
    sprite.scaleX=channel.position/snd.length;
    }
    }
    }