Skip to content

Seat Favorites#

The Favorite functionality is a subpart of the playlist; all favorites are saved as a playlist named pac_favorite. We can create our playlist with our name. The Seat favorite functionality works without pairing with PED. This API is also useful when favorites are getting through passenger manifest data.

Step 1: Initialize the PlaylistManager#

The PlayListManager class has a static method called initService, The IInFlightCallback callback provides the PlayListManager object after successfully initializing the playlist manager; otherwise, onInitServiceFailed gets called.

 PlaylistManager.initService(this, new IInFlightCallback() {
            @Override
            public void onInitServiceComplete(Object o, String s) {
                mPlaylistMgr = (PlaylistManager) o;
                if (mPlaylistMgr != null) {
        Log.v(TAG, "initialize mPlaylistMgr succeed.");
                } else {
                    Log.e(TAG, "initialize mPlaylistMgr failed.");
                }
            }

            @Override
            public void onInitServiceFailed(String s, InFlight.Error error) {
     Log.e(TAG, "initialize mPlaylistMgr failed.");
            }
        }, new InFlight());

Step 2: Set the listener to listen to the synchronization updates#

This is useful when a favorite is modified either through the PED or the IFE system. The PlayListManager class has a method setSyncListener to register the listener called Sync.SyncListener. The Sync.SyncListener provides various callbacks like onUserDataChanged, onConflict, onSyncFinished, and onSyncFailed.

mPlaylistMgr.setSyncListener(mSyncListener);
Sync.SyncListener mSyncListener = new Sync.SyncListener() {
        @Override
        public void onUserDataChanged() {
            //Invoked when synchronized data has changed.
  }

        @Override
        public void onConflict(List<? extends ConflictItem> list) {
            //Invoked when conflict occurs while synchronizing the user data.
        }

        @Override
        public void onSyncFinished(Date date) {
            //Invoked when the synchronization completes.
        }

        @Override
        public void onSyncFailed(SyncError syncError) {
            //Invoked when an error occurs during synchronization.
        }
    };

Step 3: Get a list of favorite items#

The PlayListManager class has the getFavoritesList method, which provides the Playlist class object. The Playlist class has various methods with the help of it we can perform add, and remove favorite operations. Similarly, we can also retrieve the custom playlist by using the playlist name for we can use getPlaylistByName, this method requires the playlist name.

 // To get Favorite list
 Playlist favoriteList = mPlaylistMgr.getFavoritesList();

// To get custom playlist
Playlist ownPlayList = mPlaylistMgr.getPlaylistByName("playlistName");

Step 4: Perform various favorite operations#

The PlayListManager class provides a PlayList object using the getFavoritesList method. The PlayList class has various methods with the help we can perform various operations of the favorite list. The custom playlist also operates in the same way.

4.1 Add a single item to the playlist

To add a single item to the favorite list we have an add method, this method adds the item at the end of the list. The method verifies the content is not currently in the playlist. The method returns true if added.

 JSONObject json = new JSONObject();
 json.put("media_uri", mediaUri.getText().toString());
 json.put("parent_media_uri", parentMediaUri.getText().toString().trim());
 json.put("content_type", contentType.getText().toString());
 favoriteList.add(new PlaylistItem(json));

Parameter

  1. PlaylistItem - Object of a PlaylistItem, we need to set various values like mediaUri, parentUri, etc using this object.

4.2. Add a multiple item to the favorite

To add multiple items to the favorite list, we have an overloaded version of the add method which accepts the list of PlayListItem. The items are added at the end of the queue. The method returns an int value that denotes the number of items added to the list.

PlayListItem itemOne = new PlayListItem("mediaUri1");
PlayListItem itemTwo = new PlayListItem("mediaUri2");
PlayListItem itemThree = new PlayListItem("mediaUri2");

List<PlayListItem> playListItemList = new ArrayList();
playListItemList.add(itemOne);
playListItemList.add(itemTwo);
playListItemList.add(itemThree);

favoriteList.add(playListItem);

Parameter

  1. List playlistItems - List of PlayListItem

4.3. Remove favorite from the playlist

4.3.1 Remove the favorite item using the playlist item

This method is useful for removing favorites from the playlist. It returns true if an item is successfully removed from the list; otherwise, it returns false. Multiple versions of the remove method are available, allowing items to be removed using playListItemId, a PlayListItem object, or a list of PlayListItem objects.

favoriteList.remove(playlistItem);

Parameter

  1. PlaylistItem - Object of PlayListitem that is to be removed from the list.

4.3.2 Remove favorite using playListItemId

To remove favorites from the playlist using playlist Item Id, we can use this method. If an item is removed from the list then returns true otherwise false

Parameter

  1. String: playlistItemId - Id of playlist item that is to be removed from the playlist.
 favoriteList.remove(playlistItemId);

4.3.3 Remove multiple favorite items from the playlist

To remove the multiple favorite items from the list we need to pass the list of playlistItemId. The method returns an int value that denotes the number of items removed from the playlist.

Parameter

  1. List playlistItemIds - List of playListItemIds
favoriteList.remove(playlistItemIdList);

4.4. Clear playlist

To clear the playlist, we can use the clear method. It doesn't require any parameter, also it doesn't return any value.

favoriteList.clear();

4.5. Get a list of all favorite items

To get a list of all items available in the playlist we can use the getItems method, the method returns List. The method doesn't accept any parameter

List<PlaylistItem> playlistItems = favoriteList.getItems();

4.6. Get a favorite list by content type

To get a list of items available in the playlist by their content type we can use the getItemsByContentType. The method returns the List

Parameter

  1. String contentType - any content type as string value like movies, track, etc.
List<PlaylistItem> favoriteList = favoriteList.getItemsByContentType("media.video.movie");

Version 1.0