コード例 #1
0
        public void PauseSound(string soundName)
        {
            ISound sound = FindSound(soundName);

            if (sound != null)
            {
                sound.Pause();
            }
        }
コード例 #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            //Yse.Yse.System().init();
            //Global = new YSE.Global(Yse.Yse.System());
            Y = new YSE.YseInterface(OnMessage);
            Y.System.Init();

            FileManager = Y.BufferIO as YSE.BufferIO;

            byte[] fileBuffer = default(byte[]);
            using (StreamReader sr = new StreamReader(Assets.Open("countdown.ogg")))
            {
                using (var memstream = new MemoryStream())
                {
                    sr.BaseStream.CopyTo(memstream);
                    fileBuffer = memstream.ToArray();
                }
            }

            FileManager.AddBuffer("file1", fileBuffer, fileBuffer.Length);
            FileManager.Active = true;

            sound = new YSE.Sound();
            sound.Create("file1");

            TimerCallback callback = new TimerCallback(Update);

            timer = new Timer(callback, null, 50, 50);

            // Get our button from the layout resource,
            // and attach an event to it
            Button startbutton = FindViewById <Button>(Resource.Id.startButton);

            startbutton.Click += delegate {
                sound.Play();
                Y.System.AudioTest = true;
                startbutton.Text   = "" + sound.Length;
            };

            Button pausebutton = FindViewById <Button>(Resource.Id.pauseButton);

            pausebutton.Click += delegate { sound.Pause(); };

            Button stopbutton = FindViewById <Button>(Resource.Id.stopButton);

            stopbutton.Click += delegate {
                sound.Stop();
                Y.System.AudioTest = false;
            };
        }
コード例 #3
0
ファイル: SoundSystem.cs プロジェクト: chrwoizi/canyonshooter
        /// <summary>
        /// Turn on the music box and play randomized
        /// background music.
        /// </summary>
        /// <param name="status">The new music box status</param>
        public void MusicBox(MusicBoxStatus status)
        {
            currentStatus = status;
            int i = 0;

            switch (currentStatus)
            {
            case MusicBoxStatus.Play:
                // Statemachine PLAY
                if (currentTrack != null && currentTrack.Playing() == true)
                {
                    currentTrack.Stop();
                }
                // if no music is playing, create random and play
                if (currentTrack == null || currentTrack.Playing() == false)
                {
                    // New index not the same
                    int t;
                    while ((t = rnd.Next(0, mtracks)) == midx)
                    {
                    }
                    midx = t;
                    // Load new track
                    foreach (KeyValuePair <string, SoundType> s in lib)
                    {
                        if (s.Value == SoundType.Music)
                        {
                            if (midx == i)
                            {
                                currentTrack = CreateSound(s.Key);
                                break;
                            }
                            i++;
                        }
                    }
                }
                if (!currentTrack.Playing())
                {
                    currentTrack.Play();
                    DisplayArtistName();
                }
                break;

            case MusicBoxStatus.Stop:
                // Statemachine STOP
                currentTrack.Stop();
                break;

            case MusicBoxStatus.Pause:
                // Statemachine PAUSE
                currentTrack.Pause();
                break;
            }
        }