Search in sources :

Example 1 with AudioFocusHelper

use of com.quran.labs.androidquran.service.util.AudioFocusHelper in project quran_android by quran.

the class AudioService method onCreate.

@Override
public void onCreate() {
    Timber.i("debug: Creating service");
    handler = new ServiceHandler(this);
    final Context appContext = getApplicationContext();
    ((QuranApplication) appContext).getApplicationComponent().inject(this);
    wifiLock = ((WifiManager) appContext.getSystemService(Context.WIFI_SERVICE)).createWifiLock(WifiManager.WIFI_MODE_FULL, "QuranAudioLock");
    notificationManager = (NotificationManager) appContext.getSystemService(NOTIFICATION_SERVICE);
    // create the Audio Focus Helper, if the Audio Focus feature is available
    audioFocusHelper = new AudioFocusHelper(appContext, this);
    broadcastManager = LocalBroadcastManager.getInstance(appContext);
    noisyAudioStreamReceiver = new NoisyAudioStreamReceiver();
    registerReceiver(noisyAudioStreamReceiver, new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY));
    ComponentName receiver = new ComponentName(this, MediaButtonReceiver.class);
    mediaSession = new MediaSessionCompat(appContext, "QuranMediaSession", receiver, null);
    mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mediaSession.setCallback(new MediaSessionCallback());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        setupNotificationChannel();
    }
    notificationColor = ContextCompat.getColor(this, R.color.audio_notification_color);
    try {
        // for Android Wear, use a 1x1 Bitmap with the notification color
        displayIcon = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(displayIcon);
        canvas.drawColor(notificationColor);
    } catch (OutOfMemoryError oom) {
        Crashlytics.logException(oom);
    }
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) AudioFocusHelper(com.quran.labs.androidquran.service.util.AudioFocusHelper) Canvas(android.graphics.Canvas) ComponentName(android.content.ComponentName) MediaSessionCompat(android.support.v4.media.session.MediaSessionCompat)

Aggregations

ComponentName (android.content.ComponentName)1 Context (android.content.Context)1 IntentFilter (android.content.IntentFilter)1 Canvas (android.graphics.Canvas)1 MediaSessionCompat (android.support.v4.media.session.MediaSessionCompat)1 AudioFocusHelper (com.quran.labs.androidquran.service.util.AudioFocusHelper)1