コード例 #1
0
        private void CleanUpSound(ref FMOD.Sound fmodSound)
        {
            this.timer.Stop();

            this.State = PlayerState.Stop;
            this.CurrentMediaFile = null;

            if (this.channelInfo != null)
            {
                this.channelInfo.CleanUp();
                this.channelInfo = null;
                this.system.update().ERRCHECK();
            }

            if (fmodSound != null)
            {
                fmodSound.release().ERRCHECK();
                fmodSound = null;
                this.system.update().ERRCHECK();
            }

            this.LengthMs = 0;
            this.CurrentPositionMs = 0;
        }
コード例 #2
0
        public void Play(IMediaFile file)
        {
            this.CleanUpSound(ref this.sound);

            this.CurrentMediaFile = file;

            var mode = FMOD.MODE.DEFAULT | FMOD.MODE._2D | FMOD.MODE.CREATESTREAM | FMOD.MODE.LOOP_OFF;
            if (file.IsVBR)
            {
                mode |= FMOD.MODE.ACCURATETIME;
            }

            if (!this.system.createSound(file.FullFileName, mode, out this.sound).ERRCHECK())
            {
                return;
            }

            uint lenms;
            this.sound.getLength(out lenms, FMOD.TIMEUNIT.MS).ERRCHECK();
            this.LengthMs = lenms;

            // start paused for better results
            FMOD.Channel channel;
            if (!this.system.playSound(this.sound, null, true, out channel).ERRCHECK())
            {
                return;
            }
            if (channel == null)
            {
                return;
            }

            this.channelInfo = new ChannelInfo(channel, file, this.PlayNextFileAction);

            this.system.update().ERRCHECK();

            // now start the music
            this.timer.Start();

            this.State = PlayerState.Play;
            file.State = PlayerState.Play;

            channel.setPaused(false).ERRCHECK();

            this.system.update().ERRCHECK();
        }