Android AssetFileDescriptor - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android AssetFileDescriptor class.

This code example shows how to use the following methods: getFileDescriptor, getLength, getStartOffset
	 
	public PGPolyphonicVoice( AssetFileDescriptor afd )  throws IOException
	{ 
		state = INVALID;
		mp = new MediaPlayer();
		mp.setDataSource( afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
		mp.setAudioStreamType(AudioManager.STREAM_MUSIC);  
		mp.prepare();
	} 
	 
	public void play() throws IOException 
	{ 
		invokePlay( false ); 
	} 
	 
	private void invokePlay( Boolean loop )
	{ 
		Boolean playing = ( mp.isLooping() || mp.isPlaying() );
		if ( playing )
		{ 
Full Snippet Info
10
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getFileDescriptor, getLength, getStartOffset, sleep
    //Load midi file from resources 
    public static boolean resourcesPlayback(AssetFileDescriptor afd, int expectedDuration){
        int duration = 0;
        try{ 
            MediaPlayer mp = new MediaPlayer();
            mp.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(), afd.getLength());
            mp.prepare();
            mp.start();
            duration = mp.getDuration();
            Thread.sleep(5000);
            mp.release();
        }catch (Exception e){
            Log.v(TAG,e.getMessage());
        } 
        if (duration > expectedDuration)
            return true; 
        else 
            return false; 
    } 
 
Full Snippet Info
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: close, getFileDescriptor, getLength, getStartOffset
This code example shows how to use the following methods: getFileDescriptor, getLength, getStartOffset
	 
	public PGPolyphonicVoice( AssetFileDescriptor afd )  throws IOException
	{ 
		state = INVALID;
		mp = new MediaPlayer();
		mp.setDataSource( afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
		mp.setAudioStreamType(AudioManager.STREAM_MUSIC);  
		mp.prepare();
	} 
	 
	public void play() throws IOException 
	{ 
		invokePlay( false ); 
	} 
	 
	private void invokePlay( Boolean loop )
	{ 
		Boolean playing = ( mp.isLooping() || mp.isPlaying() );
		if ( playing )
		{ 
Full Snippet Info
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: createInputStream, getLength
This code example shows how to use the following methods: close, getFileDescriptor, getLength, getStartOffset
		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);
			} 
		}		 
	} 
Full Snippet Info
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: close, getFileDescriptor, getLength, getStartOffset
		 
		AssetFileDescriptor afd = m_resources.openRawResourceFd(resId);
		try { 
			player.reset();
			 
			long len = afd.getLength();
	        if (len == AssetFileDescriptor.UNKNOWN_LENGTH) {
	        	throw new IOException("no length for fd");
	        } 
	        
	        if (len > 8000) {
	        	Log.w("ResourcePlayerSourceProvider.setDataSource()", "len too big for " +filePath);
	        } 
	         
	        player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), len);
		} finally { 
			try { 
				afd.close();
			} catch (IOException e) {
				//nothing to do 

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: createOutputStream
    @Override 
    public ParcelFileDescriptor openFile(Uri uri, String mode) {
        try { 
            ParcelFileDescriptor[] pipes = ParcelFileDescriptor.createPipe();
            final ParcelFileDescriptor write = pipes[1];
            AssetFileDescriptor afd = new AssetFileDescriptor(write, 0, -1);
            new RequestHandler(getContext(), uri, afd.createOutputStream()).start();
            return pipes[0];
        } catch (IOException e) {
            Log.e(TAG, "Failed to handle request: " + uri, e);
            return null; 
        } 
    } 
 
    public static WebResourceResponse shouldInterceptRequest(Context context,
            String url) {
        try { 
            boolean useMostVisited = BrowserSettings.getInstance().useMostVisitedHomepage();
            if (useMostVisited && url.startsWith("content://")) {
                Uri uri = Uri.parse(url);
Full Snippet Info
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getFileDescriptor, getLength, getStartOffset, sleep
    //Load midi file from resources 
    public static boolean resourcesPlayback(AssetFileDescriptor afd, int expectedDuration){
        int duration = 0;
        try{ 
            MediaPlayer mp = new MediaPlayer();
            mp.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(), afd.getLength());
            mp.prepare();
            mp.start();
            duration = mp.getDuration();
            Thread.sleep(5000);
            mp.release();
        }catch (Exception e){
            Log.v(TAG,e.getMessage());
        } 
        if (duration > expectedDuration)
            return true; 
        else 
            return false; 
    } 
 
Full Snippet Info
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods: getFileDescriptor, getLength, getStartOffset
import com.iha.pongzor.framework.Sound; 
 
public class AndroidAudio implements Audio { 
    AssetManager assets;
    SoundPool soundPool;
 
    public AndroidAudio(Activity activity) {
        activity.setVolumeControlStream(AudioManager.STREAM_MUSIC);
        this.assets = activity.getAssets();
        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 + "'");
        } 
    } 
Full Snippet Info
7
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Android AssetFileDescriptor Questions & Answers:

See Code Examples for Android AssetFileDescriptor Methods: