Пример #1
0
    public void Run()
    {
        _mainWindow.IsCursorVisible = false;

        int streamId = -1;

        if (_musicPath != null)
        {
            Tig.Sound.tig_sound_alloc_stream(out streamId, tig_sound_type.TIG_ST_VOICE);
            Tig.Sound.StreamPlayMusicOnce(streamId, _musicPath, 0, true, -1);
            if (!Tig.Sound.IsStreamActive(streamId))
            {
                streamId = -1;
            }
        }

        var keyPressed = false;
        var stopwatch  = Stopwatch.StartNew();

        while (!keyPressed)
        {
            if (streamId == -1)
            {
                // Show slides for 3s without audio
                if (stopwatch.ElapsedMilliseconds >= 3000)
                {
                    break;
                }
            }
            else
            {
                // Otherwise until the stream is done
                if (!Tig.Sound.IsStreamPlaying(streamId))
                {
                    break;
                }
            }

            _device.ClearCurrentColorTarget(LinearColorA.Black);

            var movieRect = MovieRenderer.GetMovieRect(
                _device,
                _image.GetPreferredSize().Width,
                _image.GetPreferredSize().Height
                );
            _image.SetBounds(new Rectangle(
                                 (int)movieRect.X,
                                 (int)movieRect.Y,
                                 (int)movieRect.Width,
                                 (int)movieRect.Height
                                 ));
            _image.Render();

            _subtitleRenderer?.Render(stopwatch.Elapsed.TotalSeconds);

            _device.Present();

            Tig.SystemEventPump.PumpSystemEvents();

            MovieRenderer.ProcessMessages(ref keyPressed);
        }

        if (streamId != -1)
        {
            Tig.Sound.FreeStream(streamId);
        }

        _mainWindow.IsCursorVisible = true;
    }