store duration with reflection

This commit is contained in:
nilllzz 2018-03-08 19:22:23 +01:00
parent 1869eacf38
commit fb64e8dd07
3 changed files with 7 additions and 6 deletions

View File

@ -117,7 +117,7 @@ Public Class MusicManager
If _fadeIntoIntro Then If _fadeIntoIntro Then
_fadeIntoIntro = False _fadeIntoIntro = False
_introEndTime = Date.Now.AddSeconds(0) + song.Duration _introEndTime = Date.Now.AddSeconds(0) + song.Song.Duration
_isIntroStarted = True _isIntroStarted = True
MediaPlayer.IsRepeating = False MediaPlayer.IsRepeating = False
Else Else
@ -194,7 +194,7 @@ Public Class MusicManager
' if an intro was playing while the media player was paused, calc its end time ' if an intro was playing while the media player was paused, calc its end time
If MediaPlayer.State = MediaState.Paused AndAlso _isIntroStarted Then 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 End If
@ -271,7 +271,7 @@ Public Class MusicManager
FadeInto(introSong, fadeSpeed) FadeInto(introSong, fadeSpeed)
Else Else
_isIntroStarted = True _isIntroStarted = True
_introEndTime = Date.Now.AddSeconds(0) + introSong.Duration _introEndTime = Date.Now.AddSeconds(0) + introSong.Song.Duration
Play(introSong) Play(introSong)
End If End If

View File

@ -4,12 +4,13 @@ Public Class SongContainer
Public Song As Song Public Song As Song
Public Name As String Public Name As String
Public Duration As TimeSpan
Public Sub New(song As Song, name As String, duration As TimeSpan) Public Sub New(song As Song, name As String, duration As TimeSpan)
Me.Song = song Me.Song = song
Me.Name = name 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 Sub
End Class End Class

View File

@ -509,7 +509,7 @@
MediaPlayer.IsRepeating = False MediaPlayer.IsRepeating = False
If Not MusicManager.CurrentSong Is Nothing Then If Not MusicManager.CurrentSong Is Nothing Then
Me.duration = MusicManager.CurrentSong.Duration Me.duration = MusicManager.CurrentSong.Song.Duration
Else Else
Me.duration = New TimeSpan(0) Me.duration = New TimeSpan(0)
End If End If