本文整理汇总了Java中android.media.session.MediaController.Callback方法的典型用法代码示例。如果您正苦于以下问题:Java MediaController.Callback方法的具体用法?Java MediaController.Callback怎么用?Java MediaController.Callback使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.session.MediaController
的用法示例。
在下文中一共展示了MediaController.Callback方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unregister
import android.media.session.MediaController; //导入方法依赖的package包/类
private void unregister() {
for (Map.Entry<MediaSession.Token, Pair<MediaController, MediaController.Callback>> entry : mControllers.entrySet()) {
Pair<MediaController, MediaController.Callback> pair = entry.getValue();
pair.first.unregisterCallback(pair.second);
}
synchronized (mControllers) {
mControllers.clear();
}
}
示例2: registerCallback
import android.media.session.MediaController; //导入方法依赖的package包/类
/**
* Register callback with the active media session
* @param cb Clients callback class implementation
* @param handle The handle to the clients thread
*/
public void registerCallback(MediaController.Callback cb, Handler handle){
mClientCallbacks.put(handle, cb);
if(mActiveMediaController != null){
Log.d(TAG, CTAG + "Registering callback to active controller");
mActiveMediaController.registerCallback(cb, handle);
}else{
Log.e(TAG, CTAG + "Attempted to registerCallback on a null session");
}
}
示例3: setMediaSession
import android.media.session.MediaController; //导入方法依赖的package包/类
/**
* Switch the active media session to the given session name
* @param sessionName The string name of the session to switch to
*/
public void setMediaSession(String sessionName){
MediaController newSession = null;
String sessionToken = mMediaControllerSessionMap.get(sessionName);
if(sessionToken != null){
newSession = mMediaControllers.get(sessionToken);
String oldSessionToken = "";
if(mActiveMediaController != null){
oldSessionToken = mActiveMediaController.getSessionToken().toString();
}
// Only take action if the active session isn't the current one
if(newSession != null && !oldSessionToken.equals(sessionToken)){
Log.d(TAG, CTAG + "Switching to session " + sessionName);
for(Handler handle: mClientCallbacks.keySet()){
MediaController.Callback cb = mClientCallbacks.get(handle);
if(mActiveMediaController != null){
// Pause the music, if it isn't already
mActiveMediaTransport.pause();
// Unregister the old callback
mActiveMediaController.unregisterCallback(cb);
}
// Register the new callback
newSession.registerCallback(cb, handle);
}
mActiveMediaController = newSession;
mActiveMediaTransport = newSession.getTransportControls();
String packageName = mActiveMediaController.getPackageName();
Log.d(
TAG, String.format(CTAG + "Session set to %s", packageName)
);
}
}else{
Log.e(TAG, CTAG + "Requested MediaSession not found!");
}
}
示例4: unregisterCallback
import android.media.session.MediaController; //导入方法依赖的package包/类
/**
* Unregister the given callback from the active Media Controller
* @param cb Clients callback class implementation
*/
public void unregisterCallback(MediaController.Callback cb){
Log.d(TAG, CTAG + "Unregistering Callback via unregisterCallback()");
mClientCallbacks.values().remove(cb);
if(mActiveMediaController != null){
mActiveMediaController.unregisterCallback(cb);
}
}
示例5: onDestroy
import android.media.session.MediaController; //导入方法依赖的package包/类
@Override
public void onDestroy(){
super.onDestroy();
Log.d(TAG, CTAG + "onDestroy()");
// Unregister ALL callbacks
for(MediaController.Callback cb: mClientCallbacks.values()){
unregisterCallback(cb);
}
}
示例6: createMediaControllerCallback
import android.media.session.MediaController; //导入方法依赖的package包/类
public MediaController.Callback createMediaControllerCallback() {
return new ChaosflixMediaControllerCallback();
}
示例7: createMediaControllerCallback
import android.media.session.MediaController; //导入方法依赖的package包/类
public MediaController.Callback createMediaControllerCallback() {
return new MediaControllerCallback();
}
示例8: registerActiveSessionCallback
import android.media.session.MediaController; //导入方法依赖的package包/类
public void registerActiveSessionCallback(Context context, List<MediaController> controllers) {
if (controllers.size() > 0 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
controller = controllers.get(0);
sController = new WeakReference<>(controller);
if (controllerCallback != null) {
for (MediaController ctlr : controllers)
ctlr.unregisterCallback(controllerCallback);
} else {
controllerCallback = new MediaController.Callback() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onPlaybackStateChanged(PlaybackState state) {
super.onPlaybackStateChanged(state);
if (state == null)
return;
if (isInvalidPackage(controller))
return;
boolean isPlaying = state.getState() == PlaybackState.STATE_PLAYING;
if (!isPlaying) {
NotificationManager notificationManager =
((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE));
notificationManager.cancel(0);
notificationManager.cancel(8);
}
savePlayerName(controller.getPackageName(), context);
if (controller != controller)
return; //ignore inactive sessions
broadcastControllerState(context, controller, isPlaying);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onMetadataChanged(MediaMetadata metadata) {
super.onMetadataChanged(metadata);
if (controller != controller)
return;
if (metadata == null)
return;
if (isInvalidPackage(controller))
return;
savePlayerName(controller.getPackageName(), context);
broadcastControllerState(context, controller, null);
}
};
}
controller.registerCallback(controllerCallback);
if (isInvalidPackage(controller))
return;
broadcastControllerState(context, controller, null);
}
}