java - Play sound when selecting ListPreference -


i have listpreference set up, , has 4 options. wondering if possible play sound after selecting 1 of options? want make make sound ringtone after selecting listpreference, , want sample of sound play after selecting it. don't want sound play clicking button after selecting option listpreference. want play while preferencescreen open, right after selection has been made.

perhaps add listener , in callback read sound file classpath play it. hacked example (using java7) show example of playing audio file, helps:

import java.io.ioexception; import java.util.logging.level; import java.util.logging.logger; import javax.sound.sampled.audioinputstream; import javax.sound.sampled.audiosystem; import javax.sound.sampled.clip; import javax.sound.sampled.lineunavailableexception; import javax.sound.sampled.unsupportedaudiofileexception;  public class main {      public static void main(string args[]) {         clip clip;         try {             clip = audiosystem.getclip();             audioinputstream inputstream = audiosystem.getaudioinputstream(                     main.class.getresourceasstream("morse.aiff"));             clip.open(inputstream);             clip.start();             // optionally, sleep thread duration of audio clip,              // or else may not hear             thread.sleep(5000);          } catch (lineunavailableexception | unsupportedaudiofileexception | ioexception | interruptedexception ex) {             logger.getlogger(main.class.getname()).log(level.severe, null, ex);         }     } } 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -