コード例 #1
0
        public MediaPlayer(Game game)
        {
            this.game = game;
            stop      = new Button(game, new Rectangle(155, 5, 45, 45), "", delegate(int data)
            {
                stopped = true;
                pause.Texture.useTexture(Skin.skindict["mediaPY"]);
                music.pause();
            }, Skin.skindict["mediaSP"]);
            stop.manualColour = true;
            forward           = new Button(game, new Rectangle(new Point(105, 5), new Size(45, 45)), "", delegate(int data)
            {
                if (!music.Finished)
                {
                    music.stop();
                }
                pause.Texture.useTexture(Skin.skindict["mediaPS"]);
            }, Skin.skindict["mediaFF"]);
            forward.manualColour = true;
            pause = new Button(game, new Rectangle(new Point(55, 5), new Size(45, 45)), "", delegate(int data)
            {
                if (!music.Paused)
                {
                    music.pause();
                    pause.Texture.useTexture(Skin.skindict["mediaPY"]);
                }
                else
                {
                    if (stopped)
                    {
                        music.play(true);
                    }
                    else
                    {
                        music.play(false);
                    }
                    stopped = false;
                    pause.Texture.useTexture(Skin.skindict["mediaPS"]);
                }
            }, Skin.skindict["mediaPS"]);
            pause.manualColour = true;
            backward           = new Button(game, new Rectangle(new Point(5, 5), new Size(45, 45)), "", delegate(int data)
            {
                pause.Texture.useTexture(Skin.skindict["mediaPS"]);
                if (previousSongs.Count > 1)
                {
                    music.stop();
                    if (currentID - 1 == -1)
                    {
                        currentID = 0;
                    }
                    else
                    {
                        currentID--;
                    }
                    setSong(previousSongs[currentID]);
                    play();
                }
                else
                {
                    music.PositionAsMilli = 0;
                    currentID             = 0;
                }
            }, Skin.skindict["mediaFB"]);
            backward.manualColour = true;
            title = new Label(game, new Point(0, 50), "");
            Random r = new Random();

            if (SongLibrary.Songs.Count > 0)
            {
                int id;
                id = r.Next(0, SongLibrary.Songs.Count);
                setSong(id);
                play();
                previousSongs.Add(id);
                currentID = 0;
            }
            position = new Dragbar(game, new Point(10, 85), 230, false, delegate(int d)
            {
                music.PositionAsMilli = (long)((music.Length / 100) * position.getPercentScrolled());
            });
        }