Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)
MediaRouter / src / com.example.android.mediarouter / player /

Player.java

       
        1
       
       
        /*
       
       
        2
       
       
        * Copyright (C) 2013 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.example.android.mediarouter.player;
       
       
        18
       
       
       
       
        19
       
       
        import android.content.Context;
       
       
        20
       
       
        import android.support.v7.media.MediaControlIntent;
       
       
        21
       
       
        import android.support.v7.media.MediaRouter.RouteInfo;
       
       
        22
       
       
       
       
        23
       
       
        /**
       
       
        24
       
       
        * Abstraction of common playback operations of media items, such as play,
       
       
        25
       
       
        * seek, etc. Used by PlaybackManager as a backend to handle actual playback
       
       
        26
       
       
        * of media items.
       
       
        27
       
       
        */
       
       
        28
       
       
        public abstract class Player {
       
       
        29
       
       
        protected Callback mCallback;
       
       
        30
       
       
       
       
        31
       
       
        public abstract boolean isRemotePlayback();
       
       
        32
       
       
        public abstract boolean isQueuingSupported();
       
       
        33
       
       
       
       
        34
       
       
        public abstract void connect(RouteInfo route);
       
       
        35
       
       
        public abstract void release();
       
       
        36
       
       
       
       
        37
       
       
        // basic operations that are always supported
       
       
        38
       
       
        public abstract void play(final PlaylistItem item);
       
       
        39
       
       
        public abstract void seek(final PlaylistItem item);
       
       
        40
       
       
        public abstract void getStatus(final PlaylistItem item, final boolean update);
       
       
        41
       
       
        public abstract void pause();
       
       
        42
       
       
        public abstract void resume();
       
       
        43
       
       
        public abstract void stop();
       
       
        44
       
       
       
       
        45
       
       
        // advanced queuing (enqueue & remove) are only supported
       
       
        46
       
       
        // if isQueuingSupported() returns true
       
       
        47
       
       
        public abstract void enqueue(final PlaylistItem item);
       
       
        48
       
       
        public abstract PlaylistItem remove(String iid);
       
       
        49
       
       
       
       
        50
       
       
        // route statistics
       
       
        51
       
       
        public void updateStatistics() {}
       
       
        52
       
       
        public String getStatistics() { return ""; }
       
       
        53
       
       
       
       
        54
       
       
        // presentation display
       
       
        55
       
       
        public void updatePresentation() {}
       
       
        56
       
       
       
       
        57
       
       
        public void setCallback(Callback callback) {
       
       
        58
       
       
        mCallback = callback;
       
       
        59
       
       
        }
       
       
        60
       
       
       
       
        61
       
       
        public static Player create(Context context, RouteInfo route) {
       
       
        62
       
       
        Player player;
       
       
        63
       
       
        if (route != null && route.supportsControlCategory(
       
       
        64
       
       
        MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)) {
       
       
        65
       
       
        player = new RemotePlayer(context);
       
       
        66
       
       
        } else if (route != null) {
       
       
        67
       
       
        player = new LocalPlayer.SurfaceViewPlayer(context);
       
       
        68
       
       
        } else {
       
       
        69
       
       
        player = new LocalPlayer.OverlayPlayer(context);
       
       
        70
       
       
        }
       
       
        71
       
       
        player.connect(route);
       
       
        72
       
       
        return player;
       
       
        73
       
       
        }
       
       
        74
       
       
       
       
        75
       
       
        public interface Callback {
       
       
        76
       
       
        void onError();
       
       
        77
       
       
        void onCompletion();
       
       
        78
       
       
        void onPlaylistChanged();
       
       
        79
       
       
        void onPlaylistReady();
       
       
        80
       
       
        }
       
       
        81
       
       
        }