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