Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

android play sound file from assets

// MediaPlayer m; /*assume, somewhere in the global scope...*/

public void playBeep() {
    try {
        if (m.isPlaying()) {
            m.stop();
            m.release();
            m = new MediaPlayer();
        }

        AssetFileDescriptor descriptor = getAssets().openFd("beepbeep.mp3");
        m.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength());
        descriptor.close();

        m.prepare();
        m.setVolume(1f, 1f);
        m.setLooping(true);
        m.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: java singleton implementation 
Java :: replace substring at index java 
Java :: java for 
Java :: java scanner string nextline after nextint 
Java :: check self permission android write_external_storage 
Java :: does set automatically get rid of duplicates in java 
Java :: caused by: java.lang.noclassdeffounderror: org/springframework/boot/configurationprocessor/json/jsonexception 
Java :: string length solidity 
Java :: java random between two strings 
Java :: java create map 
Java :: junit vintage engine maven 
Java :: how to print an array in java 
Java :: java convert java.util.Date to LocalDate 
Java :: sum of a list using for loop in dart 
Java :: priority scheduling in java 
Java :: find number of occurrences of a substring in a string java 
Java :: generatedvalue spring boot 
Java :: how to check null and empty string in java 
Java :: rotate a linked list 
Java :: java nested loop 
Java :: timestamp with zone java 
Java :: android application subclass 
Java :: java append file 
Java :: mongodb java find all documents 
Java :: max and min value in array 
Java :: how to find absolute difference in java 
Java :: declare class constant array java 
Java :: how to create localdate object in java 
Java :: hello world program in java 
Java :: find java_home path in cmd 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =