/** * Skips over and discards a specified number of bytes from this audio input stream. * * @param n * the requested number of bytes to be skipped * @return the actual number of bytes skipped * @throws IOException * if an input or output error occurs * @see #read * @see #available */ public long skip(long n) throws IOException { return super.skip(n * inputChannels) / inputChannels; }
/** * Skips over and discards a specified number of bytes from this audio input stream. * * @param n * the requested number of bytes to be skipped * @return the actual number of bytes skipped * @throws IOException * if an input or output error occurs * @see #read * @see #available */ public long skip(long n) throws IOException { return 2 * super.skip(n / 2 * inputChannels); }
/** * Skips over and discards a specified number of bytes from this audio input stream. * * @param n * the requested number of bytes to be skipped * @return the actual number of bytes skipped * @throws IOException * if an input or output error occurs * @see #read * @see #available */ public long skip(long n) throws IOException { return super.skip(n * inputChannels) / inputChannels; }
/** * Skips over and discards a specified number of bytes from this audio input stream. * * @param n * the requested number of bytes to be skipped * @return the actual number of bytes skipped * @throws IOException * if an input or output error occurs * @see #read * @see #available */ public long skip(long n) throws IOException { return 2 * super.skip(n / 2 * inputChannels); }
private static void dumpStreamChunk(File file, String dstPath, long offset, long length) throws UnsupportedAudioFileException, IOException { AudioFileFormat fileFormat = AudioSystem.getAudioFileFormat(file); AudioInputStream inputStream = AudioSystem.getAudioInputStream(file); AudioFormat audioFormat = fileFormat.getFormat(); int bitrate = Math.round(audioFormat.getFrameSize() * audioFormat.getFrameRate() / 1000); inputStream.skip(offset * bitrate); AudioInputStream chunkStream = new AudioInputStream(inputStream, audioFormat, length * bitrate); AudioSystem.write(chunkStream, fileFormat.getType(), new File(dstPath)); inputStream.close(); chunkStream.close(); } }
@Override public long skip(final long n) throws IOException { return super.skip(n/2); } }
@Override public long skip(long nSkip) throws IOException { // only returns integral frames long skipFrames = nSkip / newFrameSize; long originalSkippedBytes = originalStream.skip(skipFrames*originalFrameSize); long skippedFrames = originalSkippedBytes/originalFrameSize; return skippedFrames * newFrameSize; }
@Override public long skip(long nSkip) throws IOException { // only returns integral frames long skipFrames = nSkip / newFrameSize; long originalSkippedBytes = originalStream.skip(skipFrames*originalFrameSize); long skippedFrames = originalSkippedBytes/originalFrameSize; return skippedFrames * newFrameSize; }
public void setMediaTime(long timestamp) { this.timestamp = timestamp; try { stream.reset(); long offset = frameSize * (timestamp / period); stream.skip(offset); } catch (IOException e) { logger.error(e); } }
public void setMediaTime(long timestamp) { this.timestamp = timestamp; try { stream.reset(); long offset = frameSize * (timestamp / period); stream.skip(offset); } catch (IOException e) { logger.error(e); } }
public void setMediaTime(long timestamp) { this.timestamp = timestamp; try { stream.reset(); long offset = frameSize * (timestamp / period); stream.skip(offset); } catch (IOException e) { logger.error(e); } }
public void setMediaTime(long timestamp) { this.timestamp = timestamp; try { stream.reset(); long offset = frameSize * (timestamp / period); stream.skip(offset); } catch (IOException e) { logger.error(e); } }
public void setMediaTime(long timestamp) { this.timestamp = timestamp; try { stream.reset(); long offset = frameSize * (timestamp / period); stream.skip(offset); } catch (IOException e) { logger.error(e); } }
public void setMediaTime(long timestamp) { this.timestamp = timestamp; try { stream.reset(); long offset = frameSize * (timestamp / period); stream.skip(offset); } catch (IOException e) { logger.error(e); } }
public void setMediaTime(long timestamp) { this.timestamp = timestamp; try { stream.reset(); long offset = frameSize * (timestamp / period); stream.skip(offset); } catch (IOException e) { logger.error(e); } }
public void setMediaTime(long timestamp) { this.timestamp = timestamp; try { stream.reset(); long offset = frameSize * (timestamp / period); stream.skip(offset); } catch (IOException e) { logger.error(e); } }
public void setMediaTime(long timestamp) { this.timestamp = timestamp; try { stream.reset(); long offset = frameSize * (timestamp / period); stream.skip(offset); } catch (IOException e) { logger.error(e); } }
public void seekSample(long sample) { open(inputFile); try { long toSkip = sample * audioInputStream.getFormat().getFrameSize(); long skipped = 0; while (skipped < toSkip) { long b = audioInputStream.skip(toSkip - skipped); if (b == 0) break; skipped += b; } } catch (IOException e) { e.printStackTrace(); } }
@Override public synchronized long skip(long nSkip) throws IOException { // only returns integral frames long sourceSkip = targetBytes2sourceBytes(nSkip); long sourceSkipped = sourceStream != null ? sourceStream.skip(sourceSkip) : 0; flush(); return sourceBytes2targetBytes(sourceSkipped); }
File soundFile = new File(this.audioFilePath); AudioInputStream originalAudioInputStream = AudioSystem.getAudioInputStream(soundFile); AudioFormat audioFormat = originalAudioInputStream.getFormat(); float startInBytes = (startTimeinMs / 1000 * audioFormat.getSampleRate() * audioFormat.getFrameSize()); float lengthInFrames = ((endTimeinMs - startTimeinMs) / 1000 * audioFormat.getSampleRate()); originalAudioInputStream.skip((long) startInBytes); AudioInputStream partAudioInputStream = new AudioInputStream(originalAudioInputStream, originalAudioInputStream.getFormat(), (long) lengthInFrames); // code to actually play the audio input stream here