AssetFileDescriptor getStartOffset - top ranked examples from Open Source projects

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

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
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
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 )
		{ 
7
CodeRank
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
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
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
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
This code example shows how to use the following methods:close, getFileDescriptor, getLength, getStartOffset
AssetFileDescriptor fileDescriptor = assetManager.openFd(filename);
  
			if (fileDescriptor != null)
			{ 
				int soundId = mainActivity.sounds.load(fileDescriptor.getFileDescriptor(), fileDescriptor.getStartOffset(), fileDescriptor.getLength(), 1);
				fileDescriptor.close();
				return soundId;
			} 
    	} catch (IOException e) {}
 
    	return 0; 
	} 
 
	public static int playSound(int soundId)
	{ 
		return mainActivity.sounds.play(soundId, 1.0f, 1.0f, 0, 0, 1.0f);
	} 
} 
6
CodeRank
This code example shows how to use the following methods:getFileDescriptor, getLength, getStartOffset

Related AssetFileDescriptor getStartOffset Questions & Answers:

getStartOffset Method Overview
Returns the byte offset where this asset entry's data starts.
See Code Examples for other Android AssetFileDescriptor Methods: