From fb64e8dd07dd1ca3401ac2fbca02e16867d1b926 Mon Sep 17 00:00:00 2001 From: nilllzz Date: Thu, 8 Mar 2018 19:22:23 +0100 Subject: [PATCH] store duration with reflection --- P3D/Resources/Sound/MusicManager.vb | 6 +++--- P3D/Resources/Sound/SongContainer.vb | 5 +++-- P3D/Screens/BattleIntroScreen.vb | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/P3D/Resources/Sound/MusicManager.vb b/P3D/Resources/Sound/MusicManager.vb index d2dee8270..ea7f7d760 100644 --- a/P3D/Resources/Sound/MusicManager.vb +++ b/P3D/Resources/Sound/MusicManager.vb @@ -117,7 +117,7 @@ Public Class MusicManager If _fadeIntoIntro Then _fadeIntoIntro = False - _introEndTime = Date.Now.AddSeconds(0) + song.Duration + _introEndTime = Date.Now.AddSeconds(0) + song.Song.Duration _isIntroStarted = True MediaPlayer.IsRepeating = False Else @@ -194,7 +194,7 @@ Public Class MusicManager ' if an intro was playing while the media player was paused, calc its end time If MediaPlayer.State = MediaState.Paused AndAlso _isIntroStarted Then - _introEndTime = Date.Now + (_currentSong.Duration - MediaPlayer.PlayPosition) + _introEndTime = Date.Now + (_currentSong.Song.Duration - MediaPlayer.PlayPosition) End If @@ -271,7 +271,7 @@ Public Class MusicManager FadeInto(introSong, fadeSpeed) Else _isIntroStarted = True - _introEndTime = Date.Now.AddSeconds(0) + introSong.Duration + _introEndTime = Date.Now.AddSeconds(0) + introSong.Song.Duration Play(introSong) End If diff --git a/P3D/Resources/Sound/SongContainer.vb b/P3D/Resources/Sound/SongContainer.vb index 47c392bbf..3e2f4842a 100644 --- a/P3D/Resources/Sound/SongContainer.vb +++ b/P3D/Resources/Sound/SongContainer.vb @@ -4,12 +4,13 @@ Public Class SongContainer Public Song As Song Public Name As String - Public Duration As TimeSpan Public Sub New(song As Song, name As String, duration As TimeSpan) Me.Song = song Me.Name = name - Me.Duration = duration + + Dim durationField = song.GetType().GetField("_duration", Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic) + durationField.SetValue(song, duration) End Sub End Class diff --git a/P3D/Screens/BattleIntroScreen.vb b/P3D/Screens/BattleIntroScreen.vb index 73b69999e..781ab0f25 100644 --- a/P3D/Screens/BattleIntroScreen.vb +++ b/P3D/Screens/BattleIntroScreen.vb @@ -509,7 +509,7 @@ MediaPlayer.IsRepeating = False If Not MusicManager.CurrentSong Is Nothing Then - Me.duration = MusicManager.CurrentSong.Duration + Me.duration = MusicManager.CurrentSong.Song.Duration Else Me.duration = New TimeSpan(0) End If