当前位置: 首页>>代码示例>>Java>>正文


Java MediaController.Callback方法代码示例

本文整理汇总了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();
    }
}
 
开发者ID:Tombarr,项目名称:Noyze,代码行数:10,代码来源:RemoteControlLollipop.java

示例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");
    }
}
 
开发者ID:tedsalmon,项目名称:DroidIBus,代码行数:15,代码来源:MusicControllerService.java

示例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!");
    }
}
 
开发者ID:tedsalmon,项目名称:DroidIBus,代码行数:39,代码来源:MusicControllerService.java

示例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);
    }
}
 
开发者ID:tedsalmon,项目名称:DroidIBus,代码行数:12,代码来源:MusicControllerService.java

示例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);
    }
}
 
开发者ID:tedsalmon,项目名称:DroidIBus,代码行数:10,代码来源:MusicControllerService.java

示例6: createMediaControllerCallback

import android.media.session.MediaController; //导入方法依赖的package包/类
public MediaController.Callback createMediaControllerCallback() {
	return new ChaosflixMediaControllerCallback();
}
 
开发者ID:NiciDieNase,项目名称:chaosflix-leanback,代码行数:4,代码来源:PlaybackHelper.java

示例7: createMediaControllerCallback

import android.media.session.MediaController; //导入方法依赖的package包/类
public MediaController.Callback createMediaControllerCallback() {
    return new MediaControllerCallback();
}
 
开发者ID:nejtv,项目名称:androidtv-sample,代码行数:4,代码来源:PlaybackControlHelper.java

示例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);
    }
}
 
开发者ID:QuickLyric,项目名称:QuickLyric,代码行数:52,代码来源:MediaControllerCallback.java


注:本文中的android.media.session.MediaController.Callback方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。