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 )
		{ 
10
CodeRank
Connect your IDE to all the code out there  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; 
    } 
 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:close, getFileDescriptor, getLength, getStartOffset
	      @Override 
	      public void onCompletion(MediaPlayer player) {
	        player.release();
	      } 
	    }); 
	    player.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
	    file.close();
	    player.setVolume(0.2f, 0.2f);
	    player.prepare();
	    player.start();
	} 
} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
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 )
		{ 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:createInputStream, getLength
            } 
            case URI_TYPE_CONTENT:
            case URI_TYPE_RESOURCE: {
                String mimeType = contentResolver.getType(uri);
                AssetFileDescriptor assetFd = contentResolver.openAssetFileDescriptor(uri, "r");
                InputStream inputStream = assetFd.createInputStream();
                long length = assetFd.getLength();
                return new OpenForReadResult(uri, inputStream, mimeType, length, assetFd);
            } 
            case URI_TYPE_DATA: {
                OpenForReadResult ret = readDataUri(uri);
                if (ret == null) {
                    break; 
                } 
                return ret;
            } 
            case URI_TYPE_HTTP:
            case URI_TYPE_HTTPS: {
                HttpURLConnection conn = httpClient.open(new URL(uri.toString()));
                conn.setDoInput(true);
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
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);
			} 
		}		 
	} 
7
CodeRank
Connect your IDE to all the code out there  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
Connect your IDE to all the code out there  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);
7
CodeRank
Connect your IDE to all the code out there  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; 
    } 
 
6
CodeRank
Connect your IDE to all the code out there  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 + "'");
        } 
    } 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Android AssetFileDescriptor Questions & Answers:

See Code Examples for Android AssetFileDescriptor Methods: