AssetManager openFd - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for AssetManager openFd method.

This code example shows how to use the following methods:open, openFd
This code example shows how to use the following methods:openFd
	/** 
	 * This implementation checks the length of the underlying AssetFileDescriptor, if available. 
	 * @see android.content.res.AssetFileDescriptor#getLength() 
	 */ 
	public long contentLength() throws IOException { 
		return assetManager.openFd(this.fileName).getLength();
	} 
 
	public String getDescription() {
		return "asset [" + this.fileName + "]";
	} 
 
	public InputStream getInputStream() throws IOException {
		InputStream inputStream = this.assetManager.open(this.fileName);
		if (inputStream == null) {
			throw new FileNotFoundException(getDescription() + " cannot be opened because it does not exist");
		} 
		return inputStream;
	} 
 
6
CodeRank
This code example shows how to use the following methods:openFd
		gameItems = new Texture(game, "BasicPangSet2.png");
		 
		try { 
			AssetManager assetManager = game.getAssets();
			 
			FIRE = sounds.load(assetManager.openFd("fire.wav"), 1);			
			POP = sounds.load(assetManager.openFd("pop.mp3"), 1);						
			STICK= sounds.load(assetManager.openFd("stick.wav"), 1);			
			HIT = sounds.load( assetManager.openFd("hit.mp3"), 1);
			BUTTON_HEIGHTLIGHT = sounds.load(assetManager.openFd("button.mp3"), 1);
		} catch(IOException e){
			throw new RuntimeException(e);
		} 
		 
		backgroundRegion = new TextureRegion(background, 0, 0, 512, 256);
		level2Region = new TextureRegion(level2, 0, 0, 351, 245);
		level3Region = new TextureRegion(level3, 0, 0, 351, 245);
		level4Region = new TextureRegion(level4, 0, 0, 351, 245);
		backgroundMenuRegion = new TextureRegion(backgroundMenu, 0, 49, 512, 256);
		 
6
CodeRank
This code example shows how to use the following methods:openFd
		gameItems = new Texture(game, "BasicPangSet2.png");
		 
		try { 
			AssetManager assetManager = game.getAssets();
			 
			FIRE = sounds.load(assetManager.openFd("fire.wav"), 1);			
			POP = sounds.load(assetManager.openFd("pop.mp3"), 1);						
			STICK= sounds.load(assetManager.openFd("stick.wav"), 1);			
			HIT = sounds.load( assetManager.openFd("hit.mp3"), 1);
			BUTTON_HEIGHTLIGHT = sounds.load(assetManager.openFd("button.mp3"), 1);
		} catch(IOException e){
			throw new RuntimeException(e);
		} 
		 
		backgroundRegion = new TextureRegion(background, 0, 0, 512, 256);
		level2Region = new TextureRegion(level2, 0, 0, 351, 245);
		level3Region = new TextureRegion(level3, 0, 0, 351, 245);
		level4Region = new TextureRegion(level4, 0, 0, 351, 245);
		backgroundMenuRegion = new TextureRegion(backgroundMenu, 0, 0, 512, 256);
		 
6
CodeRank
This code example shows how to use the following methods:openFd
	 
	public void setDataSource(MediaPlayer player, String filePath)
			throws IOException { 
		AssetFileDescriptor afd;
		 
		afd = assetMgr.openFd(filePath);
		 
		try { 
			long len = afd.getLength();
	        if (len == AssetFileDescriptor.UNKNOWN_LENGTH) {
	        	throw new IOException("no length for fd");
	        } 
	        player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), len);
		} finally { 
			try { 
				afd.close();
			} catch (IOException e) {
				//nothing to do 
				Log.w("AssetsPlayerSourceProvider", "Error when closing FileDescriptor for "
						 + filePath, e);
5
CodeRank
This code example shows how to use the following methods:openFd
		this.soundPool = new SoundPool(20, AudioManager.STREAM_MUSIC, 0);
	} 
 
	public AndroidMusic newMusic(String filename) {
		try { 
			AssetFileDescriptor assetDescriptor = assets.openFd(filename);
			return new AndroidMusic(assetDescriptor);
		} 
		catch (IOException e) {
			throw new RuntimeException("Couldn't load music '" + filename + "'");
		} 
	} 
 
	public AndroidSound newSound(String filename) {
		try { 
			AssetFileDescriptor assetDescriptor = assets.openFd(filename);
			int soundId = soundPool.load(assetDescriptor, 0);
			return new AndroidSound(soundPool, soundId);
		} 
		catch (IOException e) {
4
CodeRank
This code example shows how to use the following methods:openFd
        this.soundPool = new SoundPool(20, AudioManager.STREAM_MUSIC, 0);
    } 
 
    public Music newMusic(String filename) {
        try { 
            AssetFileDescriptor assetDescriptor = assets.openFd(filename);
            return new AndroidMusic(assetDescriptor);
        } catch (IOException e) {
            throw new RuntimeException("Couldn't load music '" + filename + "'");
        } 
    } 
     
    public Sound newSound(String filename) {
        try { 
            AssetFileDescriptor assetDescriptor = assets.openFd(filename);
            int soundId = soundPool.load(assetDescriptor, 0);
            return new AndroidSound(soundPool, soundId);
        } catch (IOException e) {
            throw new RuntimeException("Couldn't load sound '" + filename + "'");
        } 
4
CodeRank
This code example shows how to use the following methods:openFd
        this.soundPool = new SoundPool(20, AudioManager.STREAM_MUSIC, 0);
    } 
 
    public Music newMusic(String filename) {
        try { 
            AssetFileDescriptor assetDescriptor = assets.openFd(filename);
            return new AndroidMusic(assetDescriptor);
        } catch (IOException e) {
            throw new RuntimeException("Couldn't load music '" + filename + "'");
        } 
    } 
     
    public Sound newSound(String filename) {
        try { 
            AssetFileDescriptor assetDescriptor = assets.openFd(filename);
            int soundId = soundPool.load(assetDescriptor, 0);
            return new AndroidSound(soundPool, soundId);
        } catch (IOException e) {
            throw new RuntimeException("Couldn't load sound '" + filename + "'");
        } 
4
CodeRank
This code example shows how to use the following methods:openFd
        this.soundPool = new SoundPool(20, AudioManager.STREAM_MUSIC, 0);
    } 
 
    public Music newMusic(String filename) {
        try { 
            AssetFileDescriptor assetDescriptor = assets.openFd(filename);
            return new AndroidMusic(assetDescriptor);
        } catch (IOException e) {
            throw new RuntimeException("Couldn't load music '" + filename + "'");
        } 
    } 
     
    public Sound newSound(String filename) {
        try { 
            AssetFileDescriptor assetDescriptor = assets.openFd(filename);
            int soundId = soundPool.load(assetDescriptor, 0);
            return new AndroidSound(soundPool, soundId);
        } catch (IOException e) {
            throw new RuntimeException("Couldn't load sound '" + filename + "'");
        } 
4
CodeRank
This code example shows how to use the following methods:openFd
        this.soundPool = new SoundPool(20, AudioManager.STREAM_MUSIC, 0);
    } 
 
    public Music newMusic(String filename) {
        try { 
            AssetFileDescriptor assetDescriptor = assets.openFd(filename);
            return new AndroidMusic(assetDescriptor);
        } catch (IOException e) {
            throw new RuntimeException("Couldn't load music '" + filename + "'");
        } 
    } 
     
    public Sound newSound(String filename) {
        try { 
            AssetFileDescriptor assetDescriptor = assets.openFd(filename);
            int soundId = soundPool.load(assetDescriptor, 0);
            return new AndroidSound(soundPool, soundId);
        } catch (IOException e) {
            throw new RuntimeException("Couldn't load sound '" + filename + "'");
        } 
4
CodeRank

Related AssetManager openFd Questions & Answers:

openFd Method Overview
See Code Examples for other Android AssetManager Methods: