Java Code Examples for org.newdawn.slick.util.Log

The following examples show how to use org.newdawn.slick.util.Log. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: opsu-dance   Source File: Music.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create and load a piece of music (either OGG or MOD/XM)
 * @param in The stream to read the music from 
 * @param ref  The symbolic name of this music 
 * @throws SlickException Indicates a failure to read the music from the stream
 */
public Music(InputStream in, String ref) throws SlickException {
	SoundStore.get().init();
	
	try {
		if (ref.toLowerCase().endsWith(".ogg")) {
			sound = SoundStore.get().getOgg(in);
		} else if (ref.toLowerCase().endsWith(".wav")) {
			sound = SoundStore.get().getWAV(in);
		} else if (ref.toLowerCase().endsWith(".xm") || ref.toLowerCase().endsWith(".mod")) {
			sound = SoundStore.get().getMOD(in);
		} else if (ref.toLowerCase().endsWith(".aif") || ref.toLowerCase().endsWith(".aiff")) {
			sound = SoundStore.get().getAIF(in);
		} else {
			throw new SlickException("Only .xm, .mod, .ogg, and .aif/f are currently supported.");
		}
	} catch (Exception e) {
		Log.error(e);
		throw new SlickException("Failed to load music: "+ref);
	}
}
 
Example 2
/**
 * @see org.newdawn.slick.GameContainer#setMouseCursor(org.newdawn.slick.Image, int, int)
 */
public void setMouseCursor(Image image, int hotSpotX, int hotSpotY) throws SlickException {
	try {
		Image temp = new Image(get2Fold(image.getWidth()), get2Fold(image.getHeight()));
		Graphics g = temp.getGraphics();
		
		ByteBuffer buffer = BufferUtils.createByteBuffer(temp.getWidth() * temp.getHeight() * 4);
		g.drawImage(image.getFlippedCopy(false, true), 0, 0);
		g.flush();
		g.getArea(0,0,temp.getWidth(),temp.getHeight(),buffer);
		
		Cursor cursor = CursorLoader.get().getCursor(buffer, hotSpotX, hotSpotY,temp.getWidth(),temp.getHeight());
		Mouse.setNativeCursor(cursor);
	} catch (Throwable e) {
		Log.error("Failed to load and apply cursor.", e);
		throw new SlickException("Failed to set mouse cursor", e);
	}
}
 
Example 3
Source Project: opsu-dance   Source File: Image.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create an image based on a file at the specified location
 * 
 * @param ref The location of the image file to load
 * @param flipped True if the image should be flipped on the y-axis on load
 * @param f The filtering method to use when scaling this image
 * @param transparent The color to treat as transparent
 * @throws SlickException Indicates a failure to load the image
 */
public Image(String ref, boolean flipped, int f, Color transparent) throws SlickException {
	this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST;
	this.transparent = transparent;
	this.flipped = flipped;
	
	try {
		this.ref = ref;
		int[] trans = null;
		if (transparent != null) {
			trans = new int[3];
			trans[0] = (int) (transparent.r * 255);
			trans[1] = (int) (transparent.g * 255);
			trans[2] = (int) (transparent.b * 255);
		}
		texture = InternalTextureLoader.get().getTexture(ref, flipped, filter, trans);
	} catch (IOException e) {
		Log.error(e);
		throw new SlickException("Failed to load image from: "+ref, e);
	}
}
 
Example 4
/**
 * Save a single emitter to the XML file
 * 
 * @param out
 *            The location to which we should save
 * @param emitter
 *            The emitter to store to the XML file
 * @throws IOException
 *             Indicates a failure to write or encode the XML
 */
public static void saveEmitter(OutputStream out, ConfigurableEmitter emitter)
		throws IOException {
	try {
		DocumentBuilder builder = DocumentBuilderFactory.newInstance()
				.newDocumentBuilder();
		Document document = builder.newDocument();

		document.appendChild(emitterToElement(document, emitter));
		Result result = new StreamResult(new OutputStreamWriter(out,
				"utf-8"));
		DOMSource source = new DOMSource(document);

		TransformerFactory factory = TransformerFactory.newInstance();
		Transformer xformer = factory.newTransformer();
		xformer.setOutputProperty(OutputKeys.INDENT, "yes");

		xformer.transform(source, result);
	} catch (Exception e) {
		Log.error(e);
		throw new IOException("Failed to save emitter");
	}
}
 
Example 5
Source Project: opsu-dance   Source File: Mp3InputStream.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public int read(byte[] b, int off, int len) throws IOException {
	for (int i = 0; i < len; i++) {
		try {
			int value = read();
			if (value >= 0)
				b[i] = (byte) value;
			else
				return (i == 0) ? -1 : i;
		} catch (IOException e) {
			Log.error(e);
			return i;
		}
	}

	return len;
}
 
Example 6
/**
 * Initialise the PBuffer that will be used to render to
 * 
 * @throws SlickException
 */
private void init() throws SlickException {
	try {
		Texture tex = InternalTextureLoader.get().createTexture(image.getWidth(), image.getHeight(), image.getFilter());
		
		final RenderTexture rt = new RenderTexture(false, true, false, false, RenderTexture.RENDER_TEXTURE_2D, 0);
		pbuffer = new Pbuffer(screenWidth, screenHeight, new PixelFormat(8, 0, 0), rt, null);

		// Initialise state of the pbuffer context.
		pbuffer.makeCurrent();

		initGL();
		GL.glBindTexture(GL11.GL_TEXTURE_2D, tex.getTextureID());
		pbuffer.releaseTexImage(Pbuffer.FRONT_LEFT_BUFFER);
		image.draw(0,0);
		image.setTexture(tex);
		
		Display.makeCurrent();
	} catch (Exception e) {
		Log.error(e);
		throw new SlickException("Failed to create PBuffer for dynamic image. OpenGL driver failure?");
	}
}
 
Example 7
Source Project: opsu-dance   Source File: DisplayContainer.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void updateDisplayMode(int width, int height) {
	int screenWidth = nativeDisplayMode.getWidth();
	int screenHeight = nativeDisplayMode.getHeight();

	// check for larger-than-screen dimensions
	if (!OPTION_ALLOW_LARGER_RESOLUTIONS.state && (screenWidth < width || screenHeight < height)) {
		width = 800;
		height = 600;
	}

	if (!OPTION_FULLSCREEN.state) {
		boolean borderless = (screenWidth == width && screenHeight == height);
		System.setProperty("org.lwjgl.opengl.Window.undecorated", Boolean.toString(borderless));
	}

	try {
		setDisplayMode(width, height, OPTION_FULLSCREEN.state);
	} catch (Exception e) {
		bubNotifs.send(BUB_RED, "Failed to change display mode");
		Log.error("Failed to set display mode.", e);
	}
}
 
Example 8
/**
  * {@inheritDoc}
  */
 public void setMouseCursor(Image image, int hotSpotX, int hotSpotY) throws SlickException {
     try {
        Image temp = new Image(get2Fold(image.getWidth()), get2Fold(image.getHeight()));
        Graphics g = temp.getGraphics();
        
        ByteBuffer buffer = BufferUtils.createByteBuffer(temp.getWidth() * temp.getHeight() * 4);
        g.drawImage(image.getFlippedCopy(false, true), 0, 0);
        g.flush();
        g.getArea(0,0,temp.getWidth(),temp.getHeight(),buffer);
        
        Cursor cursor = CursorLoader.get().getCursor(buffer, hotSpotX, hotSpotY,temp.getWidth(),temp.getHeight());
        Mouse.setNativeCursor(cursor);
     } catch (Throwable e) {
        Log.error("Failed to load and apply cursor.", e);
throw new SlickException("Failed to set mouse cursor", e);
     }
  }
 
Example 9
/**
 * Check PNG loader property. If set the native PNG loader will
 * not be used.
 */
private static void checkProperty() {
	if (!pngLoaderPropertyChecked) {
		pngLoaderPropertyChecked = true;

		try {
			AccessController.doPrivileged(new PrivilegedAction() {
	            public Object run() {
					String val = System.getProperty(PNG_LOADER);
					if ("false".equalsIgnoreCase(val)) {
						usePngLoader = false;
					}
					
					Log.info("Use Java PNG Loader = " + usePngLoader);
					return null;
	            }
			});
		} catch (Throwable e) {
			// ignore, security failure - probably an applet
		}
	}
}
 
Example 10
Source Project: slick2d-maven   Source File: Image.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Load the image
 * 
 * @param in The input stream to read the image from
 * @param ref The name that should be assigned to the image
 * @param flipped True if the image should be flipped on the y-axis  on load
 * @param f The filter to use when scaling this image
 * @param transparent The color to treat as transparent
 * @throws SlickException Indicates a failure to load the image
 */
private void load(InputStream in, String ref, boolean flipped, int f, Color transparent) throws SlickException {
	this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST;
	
	try {
		this.ref = ref;
		int[] trans = null;
		if (transparent != null) {
			trans = new int[3];
			trans[0] = (int) (transparent.r * 255);
			trans[1] = (int) (transparent.g * 255);
			trans[2] = (int) (transparent.b * 255);
		}
		texture = InternalTextureLoader.get().getTexture(in, ref, flipped, filter, trans);
	} catch (IOException e) {
		Log.error(e);
		throw new SlickException("Failed to load image from: "+ref, e);
	}
}
 
Example 11
Source Project: opsu-dance   Source File: Fonts.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Adds and loads glyphs for a font.
 * @param font the font to add the glyphs to
 * @param s the string containing the glyphs to load
 */
public static void loadGlyphs(UnicodeFont font, String s) {
	if (s == null || s.isEmpty())
		return;

	// get set of added strings
	HashSet<String> set = loadedGlyphs.get(font);
	if (set == null) {
		set = new HashSet<String>();
		loadedGlyphs.put(font, set);
	} else if (set.contains(s))
		return;  // string already in set

	// load glyphs
	font.addGlyphs(s);
	set.add(s);
	try {
		font.loadGlyphs();
	} catch (SlickException e) {
		Log.warn(String.format("Failed to load glyphs for string '%s'.", s), e);
	}
}
 
Example 12
/**
 * Creates a new watch service instance (overwriting any previous instance),
 * registers the beatmap directory, and starts processing events.
 */
public static void create() {
	// close the existing watch service
	destroy();

	// create a new watch service
	try {
		ws = new BeatmapWatchService();
		ws.register(config.beatmapDir.toPath());
	} catch (IOException e) {
		Log.error("Could not create watch service", e);
		bubNotifs.send(BUB_RED, "Could not create watch service");
		return;
	}

	// start processing events
	ws.start();
}
 
Example 13
/**
 * Destroys the watch service instance, if any.
 * Subsequent calls to {@link #get()} will return {@code null}.
 */
public static void destroy() {
	if (ws == null)
		return;

	try {
		ws.watcher.close();
		ws.service.shutdownNow();
		ws = null;
	} catch (IOException e) {
		String msg = "An I/O exception occurred while closing the previous watch service.";
		Log.error(msg, e);
		barNotifs.send(msg);
		ws = null;
	}
}
 
Example 14
/**
 * Computes the strain values for the beatmap.
 * @return true if successful, false otherwise
 */
private boolean calculateStrainValues() {
	// Traverse hitObjects in pairs to calculate the strain value of NextHitObject from
	// the strain value of CurrentHitObject and environment.
	if (tpHitObjects.length == 0) {
		Log.warn("Can not compute difficulty of empty beatmap.");
		return false;
	}

	tpHitObject currentHitObject = tpHitObjects[0];
	tpHitObject nextHitObject;
	int index = 0;

	// First hitObject starts at strain 1. 1 is the default for strain values,
	// so we don't need to set it here. See tpHitObject.
	while (++index < tpHitObjects.length) {
		nextHitObject = tpHitObjects[index];
		nextHitObject.calculateStrains(currentHitObject);
		currentHitObject = nextHitObject;
	}

	return true;
}
 
Example 15
/**
 * @see org.newdawn.slick.BasicGame#keyPressed(int, char)
 */
public void keyPressed(int key, char c) {
	if (key == Input.KEY_ESCAPE) {
		System.exit(0);
	}
	if (key == Input.KEY_F2) {
		app.setDefaultMouseCursor();
	}
	if (key == Input.KEY_F1) {
		if (app != null) {
			try {
				app.setDisplayMode(640,480,false);		
			} catch (SlickException e) {
				Log.error(e);
			}
		}
	}
}
 
Example 16
Source Project: opsu   Source File: Music.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create and load a piece of music (either OGG or MOD/XM)
 * @param in The stream to read the music from 
 * @param ref  The symbolic name of this music 
 * @throws SlickException Indicates a failure to read the music from the stream
 */
public Music(InputStream in, String ref) throws SlickException {
	SoundStore.get().init();
	
	try {
		if (ref.toLowerCase().endsWith(".ogg")) {
			sound = SoundStore.get().getOgg(in);
		} else if (ref.toLowerCase().endsWith(".wav")) {
			sound = SoundStore.get().getWAV(in);
		} else if (ref.toLowerCase().endsWith(".xm") || ref.toLowerCase().endsWith(".mod")) {
			sound = SoundStore.get().getMOD(in);
		} else if (ref.toLowerCase().endsWith(".aif") || ref.toLowerCase().endsWith(".aiff")) {
			sound = SoundStore.get().getAIF(in);
		} else {
			throw new SlickException("Only .xm, .mod, .ogg, and .aif/f are currently supported.");
		}
	} catch (Exception e) {
		Log.error(e);
		throw new SlickException("Failed to load music: "+ref);
	}
}
 
Example 17
/**
 * Get the next transition pair that we'lluse
 * 
 * @return The pair of transitions used to enter and leave the next state
 */
public Transition[] getNextTransitionPair() {
	Transition[] pair = new Transition[2];
	
	try {
		if (transitions[index][0] != null) {
			pair[0] = (Transition) transitions[index][0].newInstance();
		}
		if (transitions[index][1] != null) {
			pair[1] = (Transition) transitions[index][1].newInstance();
		}
	} catch (Throwable e) {
		Log.error(e);
	}
	
	index++;
	if (index >= transitions.length) {
		index = 0;
	}
	
	return pair;
}
 
Example 18
Source Project: slick2d-maven   Source File: Music.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Create and load a piece of music (either OGG or MOD/XM)
 * 
 * @param ref The location of the music
 * @param streamingHint A hint to indicate whether streaming should be used if possible
 * @throws SlickException
 */
public Music(String ref, boolean streamingHint) throws SlickException {
	SoundStore.get().init();
	
	try {
		if (ref.toLowerCase().endsWith(".ogg")) {
			if (streamingHint) {
				sound = SoundStore.get().getOggStream(ref);
			} else {
				sound = SoundStore.get().getOgg(ref);
			}
		} else if (ref.toLowerCase().endsWith(".wav")) {
			sound = SoundStore.get().getWAV(ref);
		} else if (ref.toLowerCase().endsWith(".xm") || ref.toLowerCase().endsWith(".mod")) {
			sound = SoundStore.get().getMOD(ref);
		} else if (ref.toLowerCase().endsWith(".aif") || ref.toLowerCase().endsWith(".aiff")) {
			sound = SoundStore.get().getAIF(ref);
		} else {
			throw new SlickException("Only .xm, .mod, .ogg, and .aif/f are currently supported.");
		}
	} catch (Exception e) {
		Log.error(e);
		throw new SlickException("Failed to load sound: "+ref);
	}
}
 
Example 19
/**
 * @see org.newdawn.slick.Graphics#disable()
 */
protected void disable() {
	GL.flush();
	
	// Bind the texture after rendering.
	GL.glBindTexture(GL11.GL_TEXTURE_2D, image.getTexture().getTextureID());
	pbuffer.bindTexImage(Pbuffer.FRONT_LEFT_BUFFER);
	
	try {
		Display.makeCurrent();
	} catch (LWJGLException e) {
		Log.error(e);
	}
	
	SlickCallable.leaveSafeBlock();
}
 
Example 20
Source Project: opsu   Source File: Image.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Load the image
 * 
 * @param in The input stream to read the image from
 * @param ref The name that should be assigned to the image
 * @param flipped True if the image should be flipped on the y-axis  on load
 * @param f The filter to use when scaling this image
 * @param transparent The color to treat as transparent
 * @throws SlickException Indicates a failure to load the image
 */
private void load(InputStream in, String ref, boolean flipped, int f, Color transparent) throws SlickException {
	this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST;
	
	try {
		this.ref = ref;
		int[] trans = null;
		if (transparent != null) {
			trans = new int[3];
			trans[0] = (int) (transparent.r * 255);
			trans[1] = (int) (transparent.g * 255);
			trans[2] = (int) (transparent.b * 255);
		}
		texture = InternalTextureLoader.get().getTexture(in, ref, flipped, filter, trans);
	} catch (IOException e) {
		Log.error(e);
		throw new SlickException("Failed to load image from: "+ref, e);
	}
}
 
Example 21
Source Project: opsu   Source File: Mp3InputStream.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public int read(byte[] b, int off, int len) throws IOException {
	for (int i = 0; i < len; i++) {
		try {
			int value = read();
			if (value >= 0)
				b[i] = (byte) value;
			else
				return (i == 0) ? -1 : i;
		} catch (IOException e) {
			Log.error(e);
			return i;
		}
	}

	return len;
}
 
Example 22
/**
 * @see org.newdawn.slick.Graphics#enable()
 */
protected void enable() {
	SlickCallable.enterSafeBlock();
	
	try {
		if (pbuffer.isBufferLost()) {
			pbuffer.destroy();
			init();
		}

		pbuffer.makeCurrent();
	} catch (Exception e) {
		Log.error("Failed to recreate the PBuffer");
		throw new RuntimeException(e);
	}
	
	// Put the renderer contents to the texture
	GL.glBindTexture(GL11.GL_TEXTURE_2D, image.getTexture().getTextureID());
	pbuffer.releaseTexImage(Pbuffer.FRONT_LEFT_BUFFER);
	TextureImpl.unbind();
	initGL();
}
 
Example 23
/**
 * @see org.newdawn.slick.Graphics#enable()
 */
protected void enable() {
	SlickCallable.enterSafeBlock();
	
	try {
		if (pbuffer.isBufferLost()) {
			pbuffer.destroy();
			init();
		}

		pbuffer.makeCurrent();
	} catch (Exception e) {
		Log.error("Failed to recreate the PBuffer");
		Log.error(e);
		throw new RuntimeException(e);
	}
	
	// Put the renderer contents to the texture
	TextureImpl.unbind();
	initGL();
}
 
Example 24
/**
 * Computes the strain values for the beatmap.
 * @return true if successful, false otherwise
 */
private boolean calculateStrainValues() {
	// Traverse hitObjects in pairs to calculate the strain value of NextHitObject from
	// the strain value of CurrentHitObject and environment.
	if (tpHitObjects.length == 0) {
		Log.warn("Can not compute difficulty of empty beatmap.");
		return false;
	}

	tpHitObject currentHitObject = tpHitObjects[0];
	tpHitObject nextHitObject;
	int index = 0;

	// First hitObject starts at strain 1. 1 is the default for strain values,
	// so we don't need to set it here. See tpHitObject.
	while (++index < tpHitObjects.length) {
		nextHitObject = tpHitObjects[index];
		nextHitObject.calculateStrains(currentHitObject);
		currentHitObject = nextHitObject;
	}

	return true;
}
 
Example 25
Source Project: opsu-dance   Source File: Music.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create and load a piece of music (either OGG or MOD/XM)
 * 
 * @param ref The location of the music
 * @param streamingHint A hint to indicate whether streaming should be used if possible
 * @throws SlickException
 */
public Music(String ref, boolean streamingHint) throws SlickException {
	SoundStore.get().init();
	
	try {
		if (ref.toLowerCase().endsWith(".ogg") || ref.toLowerCase().endsWith(".mp3")) {
			if (streamingHint) {
				synchronized (musicLock) {
					//getting a stream ends the current stream....
					//which may cause a MusicEnded instead of of MusicSwap
					//Not that it really matters for MusicController use
					sound = SoundStore.get().getOggStream(ref);
				}
			} else {
				sound = SoundStore.get().getOgg(ref);
			}
		} else if (ref.toLowerCase().endsWith(".wav")) {
			sound = SoundStore.get().getWAV(ref);
		} else if (ref.toLowerCase().endsWith(".xm") || ref.toLowerCase().endsWith(".mod")) {
			sound = SoundStore.get().getMOD(ref);
		} else if (ref.toLowerCase().endsWith(".aif") || ref.toLowerCase().endsWith(".aiff")) {
			sound = SoundStore.get().getAIF(ref);
		} else {
			throw new SlickException("Only .xm, .mod, .ogg, and .aif/f are currently supported.");
		}
	} catch (Exception e) {
		Log.error(e);
		throw new SlickException("Failed to load sound: "+ref);
	}
}
 
Example 26
Source Project: opsu-dance   Source File: Image.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create an empty image
 * 
 * @param width The width of the image
 * @param height The height of the image
 * @param f The filter to apply to scaling the new image
 * @throws SlickException Indicates a failure to create the underlying resource
 */
public Image(int width, int height, int f) throws SlickException {
	ref = super.toString();
	this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST;
	
	try {
		texture = InternalTextureLoader.get().createTexture(width, height, this.filter);
	} catch (IOException e) {
		Log.error(e);
		throw new SlickException("Failed to create empty image "+width+"x"+height);
	}
	
	init();
}
 
Example 27
Source Project: opsu-dance   Source File: Image.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create an image from a image data source. Note that this method uses 
 * 
 * @param data The pixelData to use to create the image
 * @param f The filter to use when scaling this image
 */
public Image(ImageData data, int f) {
	try {
		this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST;
		texture = InternalTextureLoader.get().getTexture(data, this.filter);
		ref = texture.toString();
	} catch (IOException e) {
		Log.error(e);
	}
}
 
Example 28
/**
 * @see java.applet.Applet#destroy()
 */
public void destroy() {
   if (displayParent != null) {
      remove(displayParent);
   }
   super.destroy();
   
   Log.info("Clear up");
}
 
Example 29
Source Project: opsu-dance   Source File: Mp3InputStream.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public int read() throws IOException {
	if (atEnd())
		return -1;
	while (bpos / 2 >= bufLen) {
		try {
			header = bitstream.readFrame();
			if (header == null) {
				buf.clear_buffer();

				endOfStream = true;
				return -1;
			}
			buf.clear_buffer();
			decoder.decodeFrame(header, bitstream);
			bufLen = buf.getBufferLength();
			bitstream.closeFrame();
		} catch (DecoderException | BitstreamException e) {
			Log.error(e);
		}
		bpos = 0;
	}
	int npos = bpos / 2;
	bpos++;

	if (bpos % 2 == 0)
		return (buf.getBuffer()[npos] >> 8) & 0xff;
	else
		return (buf.getBuffer()[npos]) & 0xff;
}
 
Example 30
Source Project: opsu-dance   Source File: Mp3InputStream.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
	public long skip(long length) {
		if (bufLen <= 0)
			Log.warn("Mp3InputStream: skip: bufLen not yet determined.");

		int skipped = 0;
		while (skipped + bufLen * 2 < length) {
			try {
				header = bitstream.readFrame();
				if (header == null) {
//					Log.warn("Mp3InputStream: skip: header is null.");
					endOfStream = true;
					return -1;
				}

				// last frame that won't be skipped so better read it
				if (skipped + bufLen * 2 * 4 >= length || bufLen <= 0) {
					buf.clear_buffer();
					decoder.decodeFrame(header, bitstream);
					bufLen = buf.getBufferLength();
				}
				skipped += bufLen * 2 - bpos;

				bitstream.closeFrame();
				bpos = 0;
			} catch (BitstreamException | DecoderException e) {
				Log.error(e);
			}
		}
		if (bufLen * 2 - bpos > length - skipped) {
			bpos += length - skipped;
			skipped += length - skipped;
		}

		return skipped;
	}