public override bool Play(string filePath)
{
if (!_initialized)
{
return false;
}
MusicStream currentStream = GetCurrentStream();
bool result = true;
bool playbackStarted = false;
Speed = 1; // Set playback Speed to normal speed
try
{
if (currentStream != null && filePath.ToLowerInvariant().CompareTo(currentStream.FilePath.ToLowerInvariant()) == 0)
{
// Selected file is equal to current stream
// Extend detection to permit to play the file if it failed.
if (_state == PlayState.Paused || _state == PlayState.Init)
{
if (_state == PlayState.Paused)
{
// Resume paused stream
currentStream.ResumePlayback();
}
result = Bass.BASS_Start();
if (Config.MusicPlayer == AudioPlayer.Asio)
{
result = BassAsio.BASS_ASIO_ChannelReset(false, 0, BASSASIOReset.BASS_ASIO_RESET_PAUSE); // Continue playback of Paused stream
}
else if (Config.MusicPlayer == AudioPlayer.WasApi)
{
BassWasapi.BASS_WASAPI_Start();
}
if (result)
{
_state = PlayState.Playing;
if (PlaybackStateChanged != null)
{
PlaybackStateChanged(this, PlayState.Paused, _state);
}
}
return result;
}
}
else
{
// Cue support
if ((currentStream != null && currentStream.IsPlaying))
{
if (CueUtil.isCueFakeTrackFile(filePath))
{
// Only process the CUE file here, if the song belongs to the same CUE file
// When the CUE file has changed, we handle that in PlayInternal
CueFakeTrack cueFakeTrack = CueUtil.parseCueFakeTrackFileName(filePath);
if (cueFakeTrack.CueFileName.Equals(_currentCueFileName))
{
if (HandleCueFile(ref filePath, false))
{
return true;
}
}
}
}
}
// If we're not Crossfading, we want to stop the current stream at this time
if (currentStream != null && currentStream.IsPlaying)
{
if (!currentStream.IsCrossFading)
{
currentStream.FadeOutStop();
}
}
_state = PlayState.Init;
// If WASAPI is started, we might run into troubles, because of a new stream needed,
// So let's stop it here
if (Config.MusicPlayer == AudioPlayer.WasApi && BassWasapi.BASS_WASAPI_IsStarted())
{
Log.Debug("BASS: Stop WASAPI Device before start of new playback");
BassWasapi.BASS_WASAPI_Stop(true);
}
if (!PlayInternal(filePath))
{
return false;
}
if (Config.MusicPlayer == AudioPlayer.Asio && !BassAsio.BASS_ASIO_IsStarted())
{
BassAsio.BASS_ASIO_Stop();
playbackStarted = BassAsio.BASS_ASIO_Start(0);
}
else if (Config.MusicPlayer == AudioPlayer.WasApi && !BassWasapi.BASS_WASAPI_IsStarted())
{
playbackStarted = BassWasapi.BASS_WASAPI_Start();
}
else
{
if (Bass.BASS_ChannelIsActive(_mixer.BassStream) == BASSActive.BASS_ACTIVE_PLAYING)
{
playbackStarted = true;
}
else
{
playbackStarted = Bass.BASS_ChannelPlay(_mixer.BassStream, false);
}
}
MusicStream stream = GetCurrentStream();
if (stream.BassStream != 0 && playbackStarted)
{
Log.Info("BASS: playback started");
// Set the Tag Info for Web Streams
if (stream.Filetype.FileMainType == FileMainType.WebStream)
{
_tagInfo = stream.StreamTags;
}
// Slide in the Stream over the Cross fade Interval
stream.SlideIn();
GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_PLAYBACK_STARTED, 0, 0, 0, 0, 0, null);
msg.Label = stream.FilePath;
GUIWindowManager.SendThreadMessage(msg);
NotifyPlaying = true;
PlayState oldState = _state;
_state = PlayState.Playing;
if (oldState != _state && PlaybackStateChanged != null)
{
PlaybackStateChanged(this, oldState, _state);
}
if (PlaybackStart != null)
{
PlaybackStart(g_Player.MediaType.Music, filePath);
}
}
else
{
Log.Error("BASS: Unable to play {0}. Reason: {1}.", filePath,
Enum.GetName(typeof(BASSError), Bass.BASS_ErrorGetCode()));
stream.Dispose();
result = false;
}
}
catch (Exception ex)
{
result = false;
Log.Error("BASS: Play caused an exception: {0}.", ex);
}
return result;
}