private void setupNotification(final MediaInfo info) throws TransientNetworkDisconnectionException, NoConnectionException { if (null == info) { return; } if (null != mBitmapDecoderTask) { mBitmapDecoderTask.cancel(false); } Uri imgUri = null; try { if (!info.getMetadata().hasImages()) { build(info, null, mIsPlaying); return; } else { imgUri = info.getMetadata().getImages().get(0).getUrl(); if (imgUri.equals(mVideoArtUri)) { build(info, mVideoArtBitmap, mIsPlaying); return; } } } catch (CastException e) { LOGE(TAG, "Failed to build notification"); } mBitmapDecoderTask = new FetchBitmapTask() { @Override protected void onPostExecute(Bitmap bitmap) { try { mVideoArtBitmap = bitmap; build(info, mVideoArtBitmap, mIsPlaying); } catch (CastException e) { LOGE(TAG, "Failed to set notification for " + info.toString(), e); } catch (TransientNetworkDisconnectionException e) { LOGE(TAG, "Failed to set notification for " + info.toString(), e); } catch (NoConnectionException e) { LOGE(TAG, "Failed to set notification for " + info.toString(), e); } if (mVisible) { startForeground(NOTIFICATION_ID, mNotification); } if (this == mBitmapDecoderTask) { mBitmapDecoderTask = null; } } }; mBitmapDecoderTask.start(imgUri); }
/* * (non-Javadoc) * @see android.app.Service#onDestroy() */ @Override public void onDestroy() { if (null != mBitmapDecoderTask) { mBitmapDecoderTask.cancel(false); } LOGD(TAG, "onDestroy was called"); removeNotification(); if (null != mCastManager && null != mConsumer) { mCastManager.removeVideoCastConsumer(mConsumer); mCastManager = null; } }