Example usage for android.content.res AssetFileDescriptor getStartOffset

List of usage examples for android.content.res AssetFileDescriptor getStartOffset

Introduction

In this page you can find the example usage for android.content.res AssetFileDescriptor getStartOffset.

Prototype

public long getStartOffset() 

Source Link

Document

Returns the byte offset where this asset entry's data starts.

Usage

From source file:com.haomee.chat.activity.ChatActivity.java

private void playBackgroundMusic(int resId) {
    try {//from   www. ja va2s .c o m
        if (mediaPlayer_background == null) {
            mediaPlayer_background = new MediaPlayer();
        }
        mediaPlayer_background.reset();
        AssetFileDescriptor afd = this.getResources().openRawResourceFd(resId);
        if (afd != null) {
            mediaPlayer_background.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(),
                    afd.getLength());
            afd.close();
            mediaPlayer_background.setLooping(false);
            mediaPlayer_background.prepare();
            mediaPlayer_background.start();
        }

    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:net.nightwhistler.pageturner.activity.ReadingFragment.java

private void playBeep(boolean error) {

    if (!isAdded()) {
        return;/*from  w  w w.  j a va  2 s .  com*/
    }

    try {
        MediaPlayer beepPlayer = new MediaPlayer();

        String file = "beep.mp3";

        if (error) {
            file = "error.mp3";
        }

        AssetFileDescriptor descriptor = context.getAssets().openFd(file);
        beepPlayer.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(),
                descriptor.getLength());
        descriptor.close();

        beepPlayer.prepare();

        beepPlayer.start();
    } catch (Exception io) {
        //We'll manage without the beep :)
    }
}

From source file:com.aujur.ebookreader.activity.ReadingFragment.java

private void playBeep(boolean error) {

    if (!isAdded()) {
        return;//w w  w . j  a  v a  2 s  .  c o m
    }

    try {
        MediaPlayer beepPlayer = new MediaPlayer();

        String file = "beep.mp3";

        if (error) {
            file = "error.mp3";
        }

        AssetFileDescriptor descriptor = context.getAssets().openFd(file);
        beepPlayer.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(),
                descriptor.getLength());
        descriptor.close();

        beepPlayer.prepare();

        beepPlayer.start();
    } catch (Exception io) {
        // We'll manage without the beep :)
    }
}