Skip to content

Commit

Permalink
clip mem fix
Browse files Browse the repository at this point in the history
  • Loading branch information
CreedIV committed Dec 10, 2018
1 parent aef7240 commit 6b12317
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
Binary file modified bin/TranscribeEditor$1.class
Binary file not shown.
Binary file modified bin/TranscribeEditor.class
Binary file not shown.
Binary file modified bin/TranscribeUtils.class
Binary file not shown.
13 changes: 7 additions & 6 deletions src/TranscribeEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class TranscribeEditor extends Application {
AWSTranscript awsTranscript = null;

static MediaPlayer mediaPlayer = null;
Clip clip = null;

// is there a better way than to have all these floating out here?
TextArea transcriptText = new TextArea();
Expand Down Expand Up @@ -280,7 +281,10 @@ private void playWord(String id) {

try {
AudioInputStream clipStream = TranscribeUtils.createClip(audioFilename, start_time, end_time);
Clip clip = AudioSystem.getClip();
if(clip != null && clip.isOpen())
clip.close();
else if(clip == null)
clip = AudioSystem.getClip();
clip.open(clipStream);
clip.setFramePosition(0);
clip.start();
Expand Down Expand Up @@ -435,6 +439,7 @@ private void saveClip(String outfilename, String start_timeStr, String end_timeS
AudioInputStream startStream = TranscribeUtils.createClip(audioFilename, start_timeStr, end_timeStr);
File outfile = new File(outfilename);
AudioSystem.write(startStream, Type.WAVE, outfile);
startStream.close();
}catch(Exception e) {
e.printStackTrace();
}
Expand All @@ -445,31 +450,27 @@ public void playOrPause() {
}

public void playOrPause(Double start_time) {
System.out.println("playorPause");
if(audioFilename == null) { // if no mp3 file opened, provide open dialog box
audioFilename = TranscribeUtils.getAudioFile();
if(audioFilename == null)
return;
}
if(mediaPlayer == null) {
System.out.println("play with null meidaPlayer");
File file = new File(audioFilename);
Media media = new Media(file.toURI().toString());

mediaPlayer = new MediaPlayer(media);
}
if(start_time != null) {
System.out.println("play from start time");
Duration skiptime = new Duration(start_time*1_000);
mediaPlayer.stop();
mediaPlayer.setStartTime(skiptime);
mediaPlayer.seek(skiptime);
mediaPlayer.play();
}else if(mediaPlayer.statusProperty().getValue() == MediaPlayer.Status.PLAYING) {
System.out.println("pausing");
mediaPlayer.pause();
mediaPlayer.setStartTime(mediaPlayer.getCurrentTime()); // try to fix odd mediaPlayer issue, there are bugs in mediaPlayer..... it doesnt work as it should
}else {
System.out.println("playing, status : " + mediaPlayer.statusProperty().getValue());
mediaPlayer.play();
}
}
Expand Down
1 change: 1 addition & 0 deletions src/TranscribeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ static AudioInputStream createClip(String audioFilename, String start_timeStr, S
int start_frame = clip.getFramePosition();
clip.setMicrosecondPosition(end_timeL);
int end_frame = clip.getFramePosition();
clip.close();

// get size of desired portion in bytes
int bytesPerFrame = format.getFrameSize();
Expand Down

0 comments on commit 6b12317

Please sign in to comment.