Changeset 559 in josm


Ignore:
Timestamp:
2008-02-25T12:04:48+01:00 (16 years ago)
Author:
david
Message:

Fix hang when attempting to start playing beyond end of file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/AudioPlayer.java

    r557 r559  
    1212import javax.sound.sampled.DataLine;
    1313import javax.sound.sampled.SourceDataLine;
     14import java.io.IOException;
    1415import javax.swing.JOptionPane;
    1516
     
    196197                playingUrl = null;
    197198                AudioInputStream audioInputStream = null;
    198                 int nBytesRead = 0;
    199199                SourceDataLine audioOutputLine = null;
    200200                AudioFormat     audioFormat = null;
     
    214214                                case PLAYING:
    215215                                        for(;;) {
     216                                                int nBytesRead = 0;
    216217                                                nBytesRead = audioInputStream.read(abData, 0, abData.length);
    217218                                                position += nBytesRead / bytesPerSecond;
     
    252253                                                        audioFormat = audioInputStream.getFormat();
    253254                                                        DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);
    254                                                         nBytesRead = 0;
     255                                                        long nBytesRead = 0;
    255256                                                        position = 0.0;
    256257                                                        double adjustedOffset = (offset - leadIn) * calibration;
     
    265266                                                                // audioInputStream.skip(bytesToSkip);
    266267                                                                while (bytesToSkip > chunk) {
    267                                                                         bytesToSkip -= audioInputStream.skip(chunk);
     268                                                                        nBytesRead = audioInputStream.skip(chunk);
     269                                                                        if (nBytesRead <= 0)
     270                                                                                throw new IOException(tr("This is after the end of the recording"));
     271                                                                        bytesToSkip -= nBytesRead;
    268272                                                                }
    269273                                                                if (bytesToSkip > 0)
     
    295299        public static void audioMalfunction(Exception ex) {
    296300                JOptionPane.showMessageDialog(Main.parent,
    297                                 "<html><b>" +
    298                                 tr("There was an error while trying to play the sound file for this marker.") +
    299                                 "</b><br>" + ex.getClass().getName() + ":<br><i>" + ex.getMessage() + "</i></html>",
     301                                "<html><p>" + ex.getMessage() + "</p></html>",
    300302                                tr("Error playing sound"), JOptionPane.ERROR_MESSAGE);
    301303        }
Note: See TracChangeset for help on using the changeset viewer.