Hack in some slightly less insane exception handling during audio loading, such that the user can push Cancel and not be greeted by the non-error "You pressed cancel so I cancelled!"

Exception: If the user cancels FFMS indexing, it will still proceed to try the next provider, which is not entirely desirable either.

This is an ugly hack that should stay confined to the 2.1 series.

Originally committed to SVN as r5389.
This commit is contained in:
Niels Martin Hansen 2011-06-03 19:58:20 +00:00
parent 3e9316def2
commit f24eaf6587
6 changed files with 22 additions and 4 deletions

View File

@ -927,6 +927,11 @@ void AudioDisplay::SetFile(wxString file) {
// Update
UpdateImage();
}
catch (AudioProvider::CancelAudioLoadException &) {
if (player) { delete player; player = 0; }
if (provider) { delete provider; provider = 0; }
wxLogDebug(_T("AudioDisplay::SetFile: audio load cancelled"));
}
catch (const wxChar *e) {
if (player) { delete player; player = 0; }
if (provider) { delete provider; provider = 0; }

View File

@ -242,6 +242,10 @@ AudioProvider *AudioProviderFactoryManager::GetAudioProvider(wxString filename,
break;
}
}
catch (AudioProvider::CancelAudioLoadException &) {
// user doesn't want to load anyway, get out
throw;
}
catch (wxString err) { error += list[i] + _T(" factory: ") + err + _T("\n"); }
catch (const wxChar *err) { error += list[i] + _T(" factory: ") + wxString(err) + _T("\n"); }
catch (...) { error += list[i] + _T(" factory: Unknown error\n"); }

View File

@ -78,7 +78,12 @@ FFmpegSourceAudioProvider::FFmpegSourceAudioProvider(wxString filename) {
try {
LoadAudio(filename);
} catch (...) {
}
catch (CancelAudioLoadException &) {
// pass that on, so the user won't have to cancel multiple times
throw;
}
catch (...) {
Close();
throw;
}
@ -112,7 +117,7 @@ void FFmpegSourceAudioProvider::LoadAudio(wxString filename) {
TrackNumber = AskForTrackSelection(TrackList, FFMS_TYPE_AUDIO);
// if it's still -1 here, user pressed cancel
if (TrackNumber == -1)
throw _T("FFmpegSource audio provider: audio loading cancelled by user");
throw CancelAudioLoadException();
}
// generate a name for the cache file

View File

@ -96,7 +96,7 @@ HDAudioProvider::HDAudioProvider(AudioProvider *source) {
if (canceled) {
file_cache.Close();
delete[] data;
throw wxString(_T("Audio loading cancelled by user"));
throw CancelAudioLoadException();
}
}

View File

@ -103,7 +103,7 @@ RAMAudioProvider::RAMAudioProvider(AudioProvider *source) {
progress->Destroy();
if (canceled) {
Clear();
throw wxString(_T("Audio loading cancelled by user"));
throw CancelAudioLoadException();
}
}

View File

@ -77,6 +77,10 @@ public:
virtual bool AreSamplesNativeEndian() = 0;
void GetWaveForm(int *min,int *peak,int64_t start,int w,int h,int samples,float scale);
struct CancelAudioLoadException {
int dummy;
};
};