Home | History | Annotate | Download | only in newavrcp
      1 /*
      2  * Copyright 2018 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.bluetooth.avrcp;
     18 
     19 import android.media.session.MediaSession;
     20 import android.util.Log;
     21 
     22 /**
     23  * Google Play Music hides some of the metadata behind a specific key in the Extras of the
     24  * MediaDescription in the MediaSession.QueueItem. This class exists to provide alternate
     25  * methods to allow Google Play Music to match the default behaviour of MediaPlayerWrapper.
     26  */
     27 class GPMWrapper extends MediaPlayerWrapper {
     28     private static final String TAG = "NewAvrcpGPMWrapper";
     29     private static final boolean DEBUG = true;
     30 
     31     @Override
     32     boolean isMetadataSynced() {
     33         if (getQueue() == null) {
     34             return false;
     35         }
     36 
     37         // Check if currentPlayingQueueId is in the queue
     38         MediaSession.QueueItem currItem = null;
     39         for (MediaSession.QueueItem item : getQueue()) {
     40             // The item exists in the current queue
     41             if (item.getQueueId() == getActiveQueueID()) {
     42                 currItem = item;
     43                 break;
     44             }
     45         }
     46 
     47         // Check if current playing song in Queue matches current Metadata
     48         Metadata qitem = Util.toMetadata(currItem);
     49         Metadata mdata = Util.toMetadata(getMetadata());
     50         if (currItem == null || !qitem.equals(mdata)) {
     51             if (DEBUG) {
     52                 Log.d(TAG, "Metadata currently out of sync for Google Play Music");
     53                 Log.d(TAG, "   Current queueItem: " + qitem);
     54                 Log.d(TAG, "   Current metadata : " + mdata);
     55             }
     56             return false;
     57         }
     58 
     59         return true;
     60     }
     61 }
     62