Search in sources :

Example 1 with VisualizerController

use of org.moire.ultrasonic.audiofx.VisualizerController in project ultrasonic by ultrasonic.

the class DownloadServiceImpl method onCreate.

@SuppressLint("NewApi")
@Override
public void onCreate() {
    super.onCreate();
    new Thread(new Runnable() {

        @Override
        public void run() {
            Thread.currentThread().setName("DownloadServiceImpl");
            Looper.prepare();
            if (mediaPlayer != null) {
                mediaPlayer.release();
            }
            mediaPlayer = new MediaPlayer();
            mediaPlayer.setWakeMode(DownloadServiceImpl.this, PowerManager.PARTIAL_WAKE_LOCK);
            mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {

                @Override
                public boolean onError(MediaPlayer mediaPlayer, int what, int more) {
                    handleError(new Exception(String.format("MediaPlayer error: %d (%d)", what, more)));
                    return false;
                }
            });
            try {
                Intent i = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION);
                i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, mediaPlayer.getAudioSessionId());
                i.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName());
                sendBroadcast(i);
            } catch (Throwable e) {
            // Froyo or lower
            }
            mediaPlayerLooper = Looper.myLooper();
            mediaPlayerHandler = new Handler(mediaPlayerLooper);
            Looper.loop();
        }
    }).start();
    audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
    setUpRemoteControlClient();
    if (equalizerAvailable) {
        equalizerController = new EqualizerController(this, mediaPlayer);
        if (!equalizerController.isAvailable()) {
            equalizerController = null;
        } else {
            equalizerController.loadSettings();
        }
    }
    if (visualizerAvailable) {
        visualizerController = new VisualizerController(mediaPlayer);
        if (!visualizerController.isAvailable()) {
            visualizerController = null;
        }
    }
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName());
    wakeLock.setReferenceCounted(false);
    instance = this;
    lifecycleSupport.onCreate();
}
Also used : Handler(android.os.Handler) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) SuppressLint(android.annotation.SuppressLint) PowerManager(android.os.PowerManager) VisualizerController(org.moire.ultrasonic.audiofx.VisualizerController) EqualizerController(org.moire.ultrasonic.audiofx.EqualizerController) MediaPlayer(android.media.MediaPlayer) SuppressLint(android.annotation.SuppressLint)

Example 2 with VisualizerController

use of org.moire.ultrasonic.audiofx.VisualizerController in project ultrasonic by ultrasonic.

the class VisualizerView method getVizualizer.

private static Visualizer getVizualizer() {
    DownloadService downloadService = DownloadServiceImpl.getInstance();
    VisualizerController visualizerController = downloadService == null ? null : downloadService.getVisualizerController();
    return visualizerController == null ? null : visualizerController.getVisualizer();
}
Also used : VisualizerController(org.moire.ultrasonic.audiofx.VisualizerController) DownloadService(org.moire.ultrasonic.service.DownloadService)

Aggregations

VisualizerController (org.moire.ultrasonic.audiofx.VisualizerController)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 MediaPlayer (android.media.MediaPlayer)1 Handler (android.os.Handler)1 PowerManager (android.os.PowerManager)1 EqualizerController (org.moire.ultrasonic.audiofx.EqualizerController)1 DownloadService (org.moire.ultrasonic.service.DownloadService)1