Merge pull request #4846 from peppy/fix-preview-state

Fix audio preview buttons not correctly handling load failure states
This commit is contained in:
Dan Balasescu 2019-05-23 14:25:46 +09:00 committed by GitHub
commit 48ef1ae200
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 11 deletions

View File

@ -28,7 +28,8 @@ public abstract class PreviewTrack : Component
private void load()
{
track = GetTrack();
track.Completed += () => Schedule(Stop);
if (track != null)
track.Completed += () => Schedule(Stop);
}
/// <summary>
@ -56,19 +57,25 @@ private void load()
/// <summary>
/// Starts playing this <see cref="PreviewTrack"/>.
/// </summary>
public void Start() => startDelegate = Schedule(() =>
/// <returns>Whether the track is started or already playing.</returns>
public bool Start()
{
if (track == null)
return;
return false;
if (hasStarted)
return;
startDelegate = Schedule(() =>
{
if (hasStarted)
return;
hasStarted = true;
hasStarted = true;
track.Restart();
Started?.Invoke();
});
track.Restart();
Started?.Invoke();
});
return true;
}
/// <summary>
/// Stops playing this <see cref="PreviewTrack"/>.

View File

@ -129,7 +129,7 @@ private void playingStateChanged(ValueChangedEvent<bool> e)
if (Preview != null)
{
Preview.Start();
attemptStart();
return;
}
@ -147,7 +147,7 @@ private void playingStateChanged(ValueChangedEvent<bool> e)
// user may have changed their mind.
if (Playing.Value)
preview.Start();
attemptStart();
});
}
else
@ -157,6 +157,12 @@ private void playingStateChanged(ValueChangedEvent<bool> e)
}
}
private void attemptStart()
{
if (Preview?.Start() != true)
Playing.Value = false;
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);