Example usage for android.graphics Bitmap copy

List of usage examples for android.graphics Bitmap copy

Introduction

In this page you can find the example usage for android.graphics Bitmap copy.

Prototype

public Bitmap copy(Config config, boolean isMutable) 

Source Link

Document

Tries to make a new bitmap based on the dimensions of this bitmap, setting the new bitmap's config to the one specified, and then copying this bitmap's pixels into the new bitmap.

Usage

From source file:uk.co.pjmobile.mobile_apps.page_turner_reader.ReadingActivity.java

private Bitmap getBookViewSnapshot() {

    bookView.layout(0, 0, viewSwitcher.getWidth(), viewSwitcher.getHeight());

    try {/*  ww w.j a va  2 s  .  c o m*/
        bookView.buildDrawingCache(false);
        Bitmap drawingCache = bookView.getDrawingCache();

        if (drawingCache != null) {
            Bitmap copy = drawingCache.copy(drawingCache.getConfig(), false);
            bookView.destroyDrawingCache();
            return copy;
        }

    } catch (OutOfMemoryError out) {
        viewSwitcher.setBackgroundColor(config.getBackgroundColor());
    }

    return null;
}

From source file:org.videolan.vlc.audio.AudioService.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void updateRemoteControlClientMetadata() {
    if (!LibVlcUtil.isICSOrLater()) // NOP check
        return;/*ww  w  .j  av  a  2  s.  c o m*/

    Media media = getCurrentMedia();
    if (mRemoteControlClient != null && media != null) {
        MetadataEditor editor = mRemoteControlClient.editMetadata(true);
        editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, media.getAlbum());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, media.getArtist());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_GENRE, media.getGenre());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, media.getTitle());
        editor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, media.getLength());
        // Copy the cover bitmap because the RemonteControlClient can recycle its artwork bitmap.
        Bitmap cover = getCover();
        editor.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK,
                ((cover != null) ? cover.copy(cover.getConfig(), false) : null));
        editor.apply();
    }
}

From source file:org.videolan.vlc2.audio.AudioService.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void updateRemoteControlClientMetadata() {
    if (!LibVlcUtil.isICSOrLater()) // NOP check
        return;/*  w w w . j a  v a2s  .  c  o  m*/

    Media media = getCurrentMedia();
    if (mRemoteControlClient != null && media != null) {
        MetadataEditor editor = mRemoteControlClient.editMetadata(true);
        editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, media.getAlbum());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, media.getArtist());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, media.getArtist());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_GENRE, media.getGenre());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, media.getTitle());
        editor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, media.getLength());
        // Copy the cover bitmap because the RemonteControlClient can recycle its artwork bitmap.
        Bitmap cover = getCover();
        editor.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK,
                ((cover != null) ? cover.copy(cover.getConfig(), false) : null));
        editor.apply();
    }
}

From source file:com.dzt.musicplay.player.AudioService.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void updateRemoteControlClientMetadata() {
    if (!LibVlcUtil.isICSOrLater()) // NOP check
        return;/*from   ww  w .ja v  a  2  s.co m*/

    Media media = getCurrentMedia();
    if (mRemoteControlClient != null && media != null) {
        MetadataEditor editor = mRemoteControlClient.editMetadata(true);
        editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, media.getAlbum());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, media.getArtist());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_GENRE, media.getGenre());
        editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, media.getTitle());
        editor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, media.getLength());
        // Copy the cover bitmap because the RemonteControlClient can
        // recycle its artwork bitmap.
        Bitmap cover = getCover();
        editor.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK,
                ((cover != null) ? cover.copy(cover.getConfig(), false) : null));
        editor.apply();
    }
}

From source file:org.videolan.vlc.PlaybackService.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void updateRemoteControlClientMetadata() {
    if (!AndroidUtil.isICSOrLater()) // NOP check
        return;//w  w w  .  j ava2s  . com

    MediaWrapper media = getCurrentMedia();
    if (mRemoteControlClient != null && media != null) {
        MetadataEditor editor = mRemoteControlClient.editMetadata(true);
        if (media.getNowPlaying() != null) {
            editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, "");
            editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, "");
            editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, media.getNowPlaying());
        } else {
            editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, "");
            editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, Util.getMediaAlbum(this, media));
            editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, Util.getMediaArtist(this, media));
        }
        editor.putString(MediaMetadataRetriever.METADATA_KEY_GENRE, Util.getMediaGenre(this, media));
        editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, media.getTitle());
        editor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, media.getLength());

        // Copy the cover bitmap because the RemonteControlClient can recycle its artwork bitmap.
        Bitmap cover = AudioUtil.getCover(this, media, 512);
        if (cover != null && cover.getConfig() != null) //In case of format not supported
            editor.putBitmap(MetadataEditor.BITMAP_KEY_ARTWORK, (cover.copy(cover.getConfig(), false)));

        editor.apply();
    }

    //Send metadata to Pebble watch
    if (media != null && mPebbleEnabled) {
        final Intent i = new Intent("com.getpebble.action.NOW_PLAYING");
        i.putExtra("artist", Util.getMediaArtist(this, media));
        i.putExtra("album", Util.getMediaAlbum(this, media));
        i.putExtra("track", media.getTitle());
        sendBroadcast(i);
    }
}

From source file:com.android.contacts.common.ContactPhotoManager.java

/**
 * If necessary, decodes bytes stored in the holder to Bitmap.  As long as the
 * bitmap is held either by {@link #mBitmapCache} or by a soft reference in
 * the holder, it will not be necessary to decode the bitmap.
 *//*from w  w w .  ja v  a  2  s  .co m*/
private static void inflateBitmap(BitmapHolder holder, int requestedExtent) {
    final int sampleSize = BitmapUtil.findOptimalSampleSize(holder.originalSmallerExtent, requestedExtent);
    byte[] bytes = holder.bytes;
    if (bytes == null || bytes.length == 0) {
        return;
    }

    if (sampleSize == holder.decodedSampleSize) {
        // Check the soft reference.  If will be retained if the bitmap is also
        // in the LRU cache, so we don't need to check the LRU cache explicitly.
        if (holder.bitmapRef != null) {
            holder.bitmap = holder.bitmapRef.get();
            if (holder.bitmap != null) {
                return;
            }
        }
    }

    try {
        Bitmap bitmap = BitmapUtil.decodeBitmapFromBytes(bytes, sampleSize);

        // TODO: As a temporary workaround while framework support is being added to
        // clip non-square bitmaps into a perfect circle, manually crop the bitmap into
        // into a square if it will be displayed as a thumbnail so that it can be cropped
        // into a circle.
        final int height = bitmap.getHeight();
        final int width = bitmap.getWidth();

        // The smaller dimension of a scaled bitmap can range from anywhere from 0 to just
        // below twice the length of a thumbnail image due to the way we calculate the optimal
        // sample size.
        if (height != width && Math.min(height, width) <= mThumbnailSize * 2) {
            final int dimension = Math.min(height, width);
            bitmap = ThumbnailUtils.extractThumbnail(bitmap, dimension, dimension);
        }
        // make bitmap mutable and draw size onto it
        if (DEBUG_SIZES) {
            Bitmap original = bitmap;
            bitmap = bitmap.copy(bitmap.getConfig(), true);
            original.recycle();
            Canvas canvas = new Canvas(bitmap);
            Paint paint = new Paint();
            paint.setTextSize(16);
            paint.setColor(Color.BLUE);
            paint.setStyle(Style.FILL);
            canvas.drawRect(0.0f, 0.0f, 50.0f, 20.0f, paint);
            paint.setColor(Color.WHITE);
            paint.setAntiAlias(true);
            canvas.drawText(bitmap.getWidth() + "/" + sampleSize, 0, 15, paint);
        }

        holder.decodedSampleSize = sampleSize;
        holder.bitmap = bitmap;
        holder.bitmapRef = new SoftReference<Bitmap>(bitmap);
        if (DEBUG) {
            Log.d(TAG, "inflateBitmap " + btk(bytes.length) + " -> " + bitmap.getWidth() + "x"
                    + bitmap.getHeight() + ", " + btk(bitmap.getByteCount()));
        }
    } catch (OutOfMemoryError e) {
        // Do nothing - the photo will appear to be missing
    }
}

From source file:com.chrynan.guitarchords.view.GuitarChordView.java

public Bitmap getBitmap() {
    setDrawingCacheEnabled(true);// www.  j a v a2  s.  c om
    buildDrawingCache();
    Bitmap b = getDrawingCache();
    b = b.copy(Bitmap.Config.ARGB_8888, false);
    destroyDrawingCache();
    setDrawingCacheEnabled(false);
    return b;
}

From source file:com.hotstar.player.adplayer.player.PlayerFragment.java

/**
 * Initialize the player fragment by setting up views, media player and
 * feature managers//from ww  w .j av a  2  s . co  m
 * 
 * @param intent
 *            the intent that contains the video item
 */
private void initialize(Intent intent) {
    videoItem = (VideoItem) intent.getExtras().getSerializable("CONTENT_INFO");
    AdVideoApplication.logger.i(LOG_TAG + "#initialize",
            "Initializing the media player with item [" + videoItem.getTitle() + "].");

    playerClickableAdFragment = (PlayerClickableAdFragment) getActivity().getSupportFragmentManager()
            .findFragmentById(R.id.playerClickInfo);
    playerFrame = (FrameLayout) playerFragmentView.findViewById(R.id.playerFrame);

    ViewGroup controlBarView = (ViewGroup) playerFragmentView.findViewById(R.id.ControlBarItem);
    controlBar = new PlayerControlBar(getActivity(), controlBarView);

    // ViewGroup controlTopBarView = (ViewGroup) playerFragmentView.findViewById(R.id.ControlTopBarItem);
    // controlTopBar = new PlayerControlTopBar(getActivity(), controlTopBarView);

    ViewGroup controlAdBarView = (ViewGroup) playerFragmentView.findViewById(R.id.AdControlBarItem);
    controlAdBar = new PlayerAdControlBar(getActivity(), controlAdBarView);

    spinner = (ProgressBar) playerFragmentView.findViewById(R.id.pbBufferingSpinner);

    overlayAdImageView = (ImageView) playerFragmentView.findViewById(R.id.overlayAdImageView);
    overlayAdGifView = (GifImageView) playerFragmentView.findViewById(R.id.overlayAdGifView);
    overlayAdGifView.setOnFrameAvailable(new GifImageView.OnFrameAvailable() {
        @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
        @Override
        public Bitmap onFrameAvailable(Bitmap bitmap) {
            return bitmap;
        }
    });

    java.io.InputStream is;
    is = mActivity.getResources().openRawResource(R.drawable.vpaid_ad_icon);

    vpaidAdIconGifView = (GifImageView) playerFragmentView.findViewById(R.id.vpaidAdIconGifView);
    vpaidAdIconGifView.setBytes(BytesManager.getBytes(is));
    vpaidAdIconGifView.setOnFrameAvailable(new GifImageView.OnFrameAvailable() {
        @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
        @Override
        public Bitmap onFrameAvailable(Bitmap src) {
            if (src == null)
                return src;

            int width = src.getWidth();
            int height = src.getHeight();
            Bitmap b = src.copy(Bitmap.Config.ARGB_8888, true);
            b.setHasAlpha(true);

            int[] pixels = new int[width * height];
            src.getPixels(pixels, 0, width, 0, 0, width, height);

            for (int i = 0; i < width * height; i++) {
                if ((pixels[i] == WHITE_COLOR) || (pixels[i] == BLACK_COLOR)) {
                    pixels[i] = 0;
                }
            }

            b.setPixels(pixels, 0, width, 0, 0, width, height);
            return b;
        }
    });
    vpaidAdIconGifView.setVisibility(View.INVISIBLE);
    vpaidAdIconGifView.setOnClickListener(vPaidADIconClickListener);

    thumbnailPlayImageView = (ImageView) playerFragmentView.findViewById(R.id.thumbnailPlayImageView);
    thumbnailPlayImageView.setVisibility(View.INVISIBLE);
    thumbnailImageView = (ImageView) playerFragmentView.findViewById(R.id.thumbnailImageView);
    thumbnailImageView.setVisibility(View.INVISIBLE);
    thumbnailImageView.setOnClickListener(thumbnailViewClickListener);
    OverlayAdResourceManager.getInstance().preloadImage(videoItem.getThumbnail().getLargeThumbnailUrl());

    //      audioProfile = (TextView) playerFragmentView.findViewById(R.id.audioTextView);
    //      audioProfile.setText(R.string.qosAudioProfile);
    //      audioProfile.setVisibility(View.INVISIBLE);
    //
    //      _ccButton = (ImageButton) playerFragmentView.findViewById(R.id.sbPlayerControlCC);
    //      _rewindButton = (ImageButton) playerFragmentView.findViewById(R.id.playerRewind);
    ((CustomFrameLayout) playerFrame).addOnSizeChangeListener(new OnSizeChangeListener() {

        @Override
        public void onSizeChanged() {
            // Scale player, since container size has changed.
            handler.post(new Runnable() {

                @Override
                public void run() {
                    setPlayerViewSize(savedMovieWidth, savedMovieHeight);
                }
            });
        }
    });

    createPlayer();
    setupViews();
    createManagers();
    prepareMedia();
}

From source file:com.creativeongreen.imageeffects.MainActivity.java

public static Bitmap fastblur(Bitmap bmImage, int radius) {

    // Stack Blur v1.0 from
    // http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html
    ////from   w  w w.  j  ava 2 s  . c om
    // Java Author: Mario Klingemann <mario at quasimondo.com>
    // http://incubator.quasimondo.com
    // created Feburary 29, 2004
    // Android port : Yahel Bouaziz <yahel at kayenko.com>
    // http://www.kayenko.com
    // ported april 5th, 2012

    // This is a compromise between Gaussian Blur and Box blur
    // It creates much better looking blurs than Box Blur, but is
    // 7x faster than my Gaussian Blur implementation.
    //
    // I called it Stack Blur because this describes best how this
    // filter works internally: it creates a kind of moving stack
    // of colors whilst scanning through the image. Thereby it
    // just has to add one new block of color to the right side
    // of the stack and remove the leftmost color. The remaining
    // colors on the topmost layer of the stack are either added on
    // or reduced by one, depending on if they are on the right or
    // on the left side of the stack.
    //
    // If you are using this algorithm in your code please add
    // the following line:
    //
    // Stack Blur Algorithm by Mario Klingemann <mario@quasimondo.com>

    Bitmap bmTemp = bmImage.copy(bmImage.getConfig(), true);

    if (radius < 1) {
        return (null);
    }

    int w = bmTemp.getWidth();
    int h = bmTemp.getHeight();

    int[] pix = new int[w * h];
    bmTemp.getPixels(pix, 0, w, 0, 0, w, h);

    int wm = w - 1;
    int hm = h - 1;
    int wh = w * h;
    int div = radius + radius + 1;

    int r[] = new int[wh];
    int g[] = new int[wh];
    int b[] = new int[wh];
    int rsum, gsum, bsum, x, y, i, p, yp, yi, yw;
    int vmin[] = new int[Math.max(w, h)];

    int divsum = (div + 1) >> 1;
    divsum *= divsum;
    int dv[] = new int[256 * divsum];
    for (i = 0; i < 256 * divsum; i++) {
        dv[i] = (i / divsum);
    }

    yw = yi = 0;

    int[][] stack = new int[div][3];
    int stackpointer;
    int stackstart;
    int[] sir;
    int rbs;
    int r1 = radius + 1;
    int routsum, goutsum, boutsum;
    int rinsum, ginsum, binsum;

    for (y = 0; y < h; y++) {
        rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
        for (i = -radius; i <= radius; i++) {
            p = pix[yi + Math.min(wm, Math.max(i, 0))];
            sir = stack[i + radius];
            sir[0] = (p & 0xff0000) >> 16;
            sir[1] = (p & 0x00ff00) >> 8;
            sir[2] = (p & 0x0000ff);
            rbs = r1 - Math.abs(i);
            rsum += sir[0] * rbs;
            gsum += sir[1] * rbs;
            bsum += sir[2] * rbs;
            if (i > 0) {
                rinsum += sir[0];
                ginsum += sir[1];
                binsum += sir[2];
            } else {
                routsum += sir[0];
                goutsum += sir[1];
                boutsum += sir[2];
            }
        }
        stackpointer = radius;

        for (x = 0; x < w; x++) {

            r[yi] = dv[rsum];
            g[yi] = dv[gsum];
            b[yi] = dv[bsum];

            rsum -= routsum;
            gsum -= goutsum;
            bsum -= boutsum;

            stackstart = stackpointer - radius + div;
            sir = stack[stackstart % div];

            routsum -= sir[0];
            goutsum -= sir[1];
            boutsum -= sir[2];

            if (y == 0) {
                vmin[x] = Math.min(x + radius + 1, wm);
            }
            p = pix[yw + vmin[x]];

            sir[0] = (p & 0xff0000) >> 16;
            sir[1] = (p & 0x00ff00) >> 8;
            sir[2] = (p & 0x0000ff);

            rinsum += sir[0];
            ginsum += sir[1];
            binsum += sir[2];

            rsum += rinsum;
            gsum += ginsum;
            bsum += binsum;

            stackpointer = (stackpointer + 1) % div;
            sir = stack[(stackpointer) % div];

            routsum += sir[0];
            goutsum += sir[1];
            boutsum += sir[2];

            rinsum -= sir[0];
            ginsum -= sir[1];
            binsum -= sir[2];

            yi++;
        }
        yw += w;
    }

    for (x = 0; x < w; x++) {
        rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;
        yp = -radius * w;
        for (i = -radius; i <= radius; i++) {
            yi = Math.max(0, yp) + x;

            sir = stack[i + radius];

            sir[0] = r[yi];
            sir[1] = g[yi];
            sir[2] = b[yi];

            rbs = r1 - Math.abs(i);

            rsum += r[yi] * rbs;
            gsum += g[yi] * rbs;
            bsum += b[yi] * rbs;

            if (i > 0) {
                rinsum += sir[0];
                ginsum += sir[1];
                binsum += sir[2];
            } else {
                routsum += sir[0];
                goutsum += sir[1];
                boutsum += sir[2];
            }

            if (i < hm) {
                yp += w;
            }
        }
        yi = x;
        stackpointer = radius;
        for (y = 0; y < h; y++) {
            // Preserve alpha channel: ( 0xff000000 & pix[yi] )
            pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum];

            rsum -= routsum;
            gsum -= goutsum;
            bsum -= boutsum;

            stackstart = stackpointer - radius + div;
            sir = stack[stackstart % div];

            routsum -= sir[0];
            goutsum -= sir[1];
            boutsum -= sir[2];

            if (x == 0) {
                vmin[y] = Math.min(y + r1, hm) * w;
            }
            p = x + vmin[y];

            sir[0] = r[p];
            sir[1] = g[p];
            sir[2] = b[p];

            rinsum += sir[0];
            ginsum += sir[1];
            binsum += sir[2];

            rsum += rinsum;
            gsum += ginsum;
            bsum += binsum;

            stackpointer = (stackpointer + 1) % div;
            sir = stack[stackpointer];

            routsum += sir[0];
            goutsum += sir[1];
            boutsum += sir[2];

            rinsum -= sir[0];
            ginsum -= sir[1];
            binsum -= sir[2];

            yi += w;
        }
    }

    bmTemp.setPixels(pix, 0, w, 0, 0, w, h);

    return bmTemp;
}

From source file:com.naman14.timber.musicplayer.MusicService.java

private void updateMediaSession(final String what) {
    int playState = mIsSupposedToBePlaying ? PlaybackStateCompat.STATE_PLAYING
            : PlaybackStateCompat.STATE_PAUSED;

    if (what.equals(PLAYSTATE_CHANGED) || what.equals(POSITION_CHANGED)) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mSession.setPlaybackState(new PlaybackStateCompat.Builder().setState(playState, position(), 1.0f)
                    .setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PAUSE
                            | PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_SKIP_TO_NEXT
                            | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS)
                    .build());/*  w  w  w .j  av a  2  s.  c  o  m*/
        }
    } else if (what.equals(META_CHANGED) || what.equals(QUEUE_CHANGED)) {
        //TODO: Replace below Image download using Picasso
        Bitmap albumArt = ImageLoader.getInstance()
                .loadImageSync(TimberUtils.getAlbumArtUri(getAlbumId()).toString());
        if (albumArt != null) {

            Bitmap.Config config = albumArt.getConfig();
            if (config == null) {
                config = Bitmap.Config.ARGB_8888;
            }
            albumArt = albumArt.copy(config, false);
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mSession.setMetadata(new MediaMetadataCompat.Builder()
                    .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, getArtistName())
                    .putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST, getAlbumArtistName())
                    .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, getAlbumName())
                    .putString(MediaMetadataCompat.METADATA_KEY_TITLE, getTrackName())
                    .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration())
                    .putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, getQueuePosition() + 1)
                    .putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, getQueue().size())
                    .putString(MediaMetadataCompat.METADATA_KEY_GENRE, getGenreName())
                    .putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART,
                            mShowAlbumArtOnLockscreen ? albumArt : null)
                    .build());

            mSession.setPlaybackState(new PlaybackStateCompat.Builder().setState(playState, position(), 1.0f)
                    .setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PAUSE
                            | PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_SKIP_TO_NEXT
                            | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS)
                    .build());
        }
    }
}