Skip to content

Commit

Permalink
Properly handle file not found on load.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentg committed Mar 6, 2015
1 parent e00b70a commit e297d66
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/main/java/org/truffautronic/model/AudioCue.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ public void setOutputMixer(OutputMixer outputMixer) {
volumeManager.setOutputMixer(outputMixer);
}

public void start(AudioParams audioParams) {
public boolean start(AudioParams audioParams) {
if (paused) {
pauseResume();
}
CueAudio cueAudio = cueAudioFactory.createCueAudio(volumeManager
.getOutputMixer().getAudioOutput(), audioParams, volumeManager);
if (cueAudio == null)
return;
return false;
cueAudio.setListener(this);
cueAudio.setStartMs(start.getMs());
cueAudio.setEndMs(end.getMs());
Expand All @@ -144,6 +144,7 @@ public void start(AudioParams audioParams) {
listener.audioStarted();
System.out.println("Starting a new cue: " + name);
}
return true;
}

public boolean pauseResume() {
Expand Down Expand Up @@ -188,8 +189,11 @@ public Duration getStart() {
}

public Duration getEnd() {
if (end == null)
if (end == null) {
end = cueAudioFactory.getDuration();
if (end == null)
return Duration.ZERO;
}
return end;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void setAudioFile(File audioFile) {
try {
loadAudio();
} catch (Exception e) {
System.err.println("File not found: " + audioFile);
this.audioFile = null;
}
}
Expand Down Expand Up @@ -115,6 +116,8 @@ private byte[] loadFile(File file) throws IOException {
@Override
public CueAudio createCueAudio(AudioOutput audioOutput,
AudioParams audioParams, VolumeManager volumeManager) {
if (audioData == null)
return null;
return new ClipCueAudio(audioFormat, audioData, audioOutput,
audioParams, volumeManager);
}
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/org/truffautronic/view/CueView.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,14 @@ public void actionPerformed(ActionEvent e) {
@Override
public void actionPerformed(ActionEvent e) {
pauseResumeButton.setSelected(false);
cue.start(CueView.this.scenario.getAudioParams());
boolean started = cue.start(CueView.this.scenario
.getAudioParams());
if (!started) {
JOptionPane.showMessageDialog(null,
I18N.translate("dialog.cant.start.no.audio"),
I18N.translate("dialog.title.error"),
JOptionPane.ERROR_MESSAGE);
}
}
});
// Stop button
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/Truffautronic.properties
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ dialog.rename_scene=Rename scene:
error.need_two_cues_to_reorder=Need at least two cues to reorder them.
dialog.title.reorder_cues=Reorder cues of scene {0}
dialog.title.error=Error
dialog.cant.start.no.audio=Cannot start, no audio
dialog.do_you_want_to_save=Scenario has been modified. Do you want to save it?
error.cant_load=Can''t load: {0}
error.cant_save=Can''t save: {0}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/Truffautronic_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ dialog.rename_scene=Renommer la sc
error.need_two_cues_to_reorder=Il faut au moins deux effets pour les réordonner.
dialog.title.reorder_cues=Réordonner les effets de la scène {0}
dialog.title.error=Erreur
dialog.cant.start.no.audio=Impossible de lancer la lecture, fichier audio non trouvé.
dialog.do_you_want_to_save=Le scénario à été modifié. Voulez-vous le sauvegarder?
error.cant_load=Impossible d''ouvrir: {0}
error.cant_save=Impossible de sauvegarder: {0}
Expand Down

0 comments on commit e297d66

Please sign in to comment.