/*
 * Copyright 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.media2.widget;

import android.content.Context;

import androidx.media2.MediaItem;
import androidx.media2.MediaMetadata;
import androidx.media2.MediaPlayer;

import com.google.common.util.concurrent.ListenableFuture;

import java.util.ArrayList;
import java.util.List;

class VideoViewPlayer extends MediaPlayer {
    VideoViewPlayer(Context context) {
        super(context);
    }

    private MediaItem mMediaItem;

    @Override
    public ListenableFuture<PlayerResult> seekTo(long position) {
        return super.seekTo(position, SEEK_CLOSEST);
    }

    ///////////////////////////////////////////////////////////////////////////////////////
    // Workarounds for not throwing UnsupportedOperationException.
    // TODO: Remove overrides below.
    ///////////////////////////////////////////////////////////////////////////////////////
    @Override
    public List<MediaItem> getPlaylist() {
        try {
            return super.getPlaylist();
        } catch (Exception e) {
            ArrayList<MediaItem> list = new ArrayList<>();
            list.add(getCurrentMediaItem());
            return list;
        }
    }

    @Override
    public MediaMetadata getPlaylistMetadata() {
        try {
            return super.getPlaylistMetadata();
        } catch (Exception e) {
            return null;
        }
    }

    @Override
    public int getRepeatMode() {
        try {
            return super.getRepeatMode();
        } catch (Exception e) {
            return REPEAT_MODE_NONE;
        }
    }

    @Override
    public int getShuffleMode() {
        try {
            return super.getShuffleMode();
        } catch (Exception e) {
            return SHUFFLE_MODE_NONE;
        }
    }

    @Override
    public ListenableFuture<PlayerResult> setMediaItem(MediaItem item) {
        mMediaItem = item;
        return super.setMediaItem(item);
    }

    @Override
    public MediaItem getCurrentMediaItem() {
        try {
            return super.getCurrentMediaItem();
        } catch (Exception e) {
            return mMediaItem;
        }
    }
}

@@ -680,80 +680,8 @@
 t;%0A%0A
-import androidx.media2.MediaItem;%0Aimport androidx.media2.MediaMetadata;%0A
 impo
@@ -712,16 +712,16 @@
 Player;%0A
+
 %0Aimport 
@@ -777,60 +777,8 @@
 e;%0A%0A
-import java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 clas
@@ -891,43 +891,8 @@
  %7D%0A%0A
-    private MediaItem mMediaItem;%0A%0A
     
@@ -963,24 +963,24 @@
 position) %7B%0A
+
         retu
@@ -1029,1527 +1029,7 @@
    %7D
-%0A%0A    ///////////////////////////////////////////////////////////////////////////////////////%0A    // Workarounds for not throwing UnsupportedOperationException.%0A    // TODO: Remove overrides below.%0A    ///////////////////////////////////////////////////////////////////////////////////////%0A    @Override%0A    public List%3CMediaItem%3E getPlaylist() %7B%0A        try %7B%0A            return super.getPlaylist();%0A        %7D catch (Exception e) %7B%0A            ArrayList%3CMediaItem%3E list = new ArrayList%3C%3E();%0A            list.add(getCurrentMediaItem());%0A            return list;%0A        %7D%0A    %7D%0A%0A    @Override%0A    public MediaMetadata getPlaylistMetadata() %7B%0A        try %7B%0A            return super.getPlaylistMetadata();%0A        %7D catch (Exception e) %7B%0A            return null;%0A        %7D%0A    %7D%0A%0A    @Override%0A    public int getRepeatMode() %7B%0A        try %7B%0A            return super.getRepeatMode();%0A        %7D catch (Exception e) %7B%0A            return REPEAT_MODE_NONE;%0A        %7D%0A    %7D%0A%0A    @Override%0A    public int getShuffleMode() %7B%0A        try %7B%0A            return super.getShuffleMode();%0A        %7D catch (Exception e) %7B%0A            return SHUFFLE_MODE_NONE;%0A        %7D%0A    %7D%0A%0A    @Override%0A    public ListenableFuture%3CPlayerResult%3E setMediaItem(MediaItem item) %7B%0A        mMediaItem = item;%0A        return super.setMediaItem(item);%0A    %7D%0A%0A    @Override%0A    public MediaItem getCurrentMediaItem() %7B%0A        try %7B%0A            return super.getCurrentMediaItem();%0A        %7D catch (Exception e) %7B%0A            return mMediaItem;%0A        %7D%0A    %7D
 %0A%7D%0A

Remove unnecessary overridden methods in VideoViewPlayer