• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Player类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.spotify.sdk.android.player.Player的典型用法代码示例。如果您正苦于以下问题:Java Player类的具体用法?Java Player怎么用?Java Player使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Player类属于com.spotify.sdk.android.player包,在下文中一共展示了Player类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: initializePlayer

import com.spotify.sdk.android.player.Player; //导入依赖的package包/类
private void initializePlayer() {
    SharedPreferences prefsAppData = getSharedPreferences(getString(R.string.sharedpreferences_global), Context.MODE_PRIVATE);
    if (prefsAppData.getInt(getString(R.string.responseType), -1) == AuthenticationResponse.Type.TOKEN.ordinal()) {

        Config config = new Config(
                this,
                prefsAppData.getString(getString(R.string.spotifyAccessToken_value), null),
                prefsAppData.getString(getString(R.string.clientId), null)
        );
        spotifyPlayer = Spotify.getPlayer(config, this, new Player.InitializationObserver() {
            @Override
            public void onInitialized(Player player) {
                player.addConnectionStateCallback(MainActivity.connectionStateCallback);
                player.addPlayerNotificationCallback(TracksActivity.this);
            }

            @Override
            public void onError(Throwable throwable) {
                Log.e("PLAYER", "ERROR: " + throwable.getMessage());
            }
        });

    }
}
 
开发者ID:sharaquss,项目名称:Betterfy,代码行数:25,代码来源:TracksActivity.java


示例2: startPlayer

import com.spotify.sdk.android.player.Player; //导入依赖的package包/类
/***
 * @param context
 * @param token                      : Spotify token needed to use the api
 * @param observer                   : used to know when player is ready
 * @param playerNotificationCallback
 * @param connectionStateCallback
 */
public static void startPlayer(final Context context, String token, final Player.InitializationObserver observer, @Nullable final PlayerNotificationCallback playerNotificationCallback, @Nullable final ConnectionStateCallback connectionStateCallback) {
    SpotifyPlayerManager.context = context;
    Config playerConfig = new Config(context, token, SpotifyManager.API_KEY);
    setConnectionStateCallback(connectionStateCallback);
    setPlayerNotificationCallback(playerNotificationCallback);
    Spotify.getPlayer(playerConfig, context, new Player.InitializationObserver() {
        @Override
        public void onInitialized(Player pl) {
            player = pl;
            if (connectionStateCallback != null)
                player.addConnectionStateCallback(SpotifyManager.connectionStateCallback);
            if (playerNotificationCallback != null)
                player.addPlayerNotificationCallback(SpotifyManager.playerNotificationCallback);
            observer.onInitialized(player);
        }

        @Override
        public void onError(Throwable throwable) {
            Log.e(SpotifyManager.class.getSimpleName(), "Could not initialize player: " + throwable.getMessage());
            observer.onError(throwable);

        }
    });
}
 
开发者ID:joxad,项目名称:android-easy-spotify,代码行数:32,代码来源:SpotifyPlayerManager.java


示例3: playNext

import com.spotify.sdk.android.player.Player; //导入依赖的package包/类
private void playNext() {
    tracklistRepository.getFirstSong(partyTitle)
        .subscribe(song -> {
            spotifyPlayer.playUri(new Player.OperationCallback() {
                @Override
                public void onSuccess() {
                    Log.d(LogTag.LOG_HOST_SERVICE, "Playing next song in tracklist");
                    isTracklistEmpty = false;
                }

                @Override
                public void onError(Error error) {
                    Log.d(LogTag.LOG_HOST_SERVICE, "Failed to play next song in tracklist: " + error.name());
                    sendPlayingStatusBroadcast(false);
                }
            }, song.getSongUri(), 0, 0);
        }, throwable -> {
            Log.d(LogTag.LOG_HOST_SERVICE, "Could not play next song: " + throwable.getMessage());
            sendPlayingStatusBroadcast(false);
            if (throwable instanceof EmptyTracklistException) {
                isTracklistEmpty = true;
            }
        });
}
 
开发者ID:ZinoKader,项目名称:SpotiQ,代码行数:25,代码来源:SpotiqHostService.java


示例4: startSpotifySession

import com.spotify.sdk.android.player.Player; //导入依赖的package包/类
public void startSpotifySession(final Activity activity, String accessToken, final Runnable onStarted, final Runnable onFailed) {
    // Spotify API
    SpotifyApi api = new SpotifyApi();
    api.setAccessToken(accessToken);
    mSpotifyService = api.getService();

    // Spotify Player Controller
    String clientId = getString(R.string.spotify_client_id);
    Config playerConfig = new Config(this, accessToken, clientId);
    Player player = Spotify.getPlayer(playerConfig, this, null);
    mSpotifyPlayerController = new SpotifyPlayerController(player, mSpotifyService);

    mSpotifyService.getMe(new Callback<UserPrivate>() {
        @Override
        public void success(UserPrivate user, Response response) {
            saveCurrentUser(user);
            activity.runOnUiThread(onStarted);
        }

        @Override
        public void failure(RetrofitError error) {
            activity.runOnUiThread(onFailed);
        }
    });
}
 
开发者ID:sregg,项目名称:spotify-tv,代码行数:26,代码来源:SpotifyTvApplication.java


示例5: SpotifyPlayerController

import com.spotify.sdk.android.player.Player; //导入依赖的package包/类
public SpotifyPlayerController(Player player, SpotifyService spotifyService) {
    context = SpotifyTvApplication.getInstance().getApplicationContext();
    mHandler = new Handler(context.getMainLooper());
    mUserPreferences = UserPreferences.getInstance(context);

    audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    mPlayer = player;

    mPlayer.addPlayerNotificationCallback(this);
    mPlayer.addConnectionStateCallback(this);
    setPlayerBitrate(mUserPreferences.getBitrate());
    setShuffle(mUserPreferences.getShuffle());

    mediaSessionController = new MediaPlayerSessionController(context, this);

    mSpotifyService = spotifyService;

    // init playing state with dummy data
    resetPlayingState();
}
 
开发者ID:sregg,项目名称:spotify-tv,代码行数:21,代码来源:SpotifyPlayerController.java


示例6: pause

import com.spotify.sdk.android.player.Player; //导入依赖的package包/类
private void pause() {
    spotifyPlayer.pause(new Player.OperationCallback() {
        @Override
        public void onSuccess() {
            Log.d(LogTag.LOG_HOST_SERVICE, "Paused music successfully");
        }

        @Override
        public void onError(Error error) {
            Log.d(LogTag.LOG_HOST_SERVICE, "Failed to pause music");
        }
    });
}
 
开发者ID:ZinoKader,项目名称:SpotiQ,代码行数:14,代码来源:SpotiqHostService.java


示例7: resume

import com.spotify.sdk.android.player.Player; //导入依赖的package包/类
private void resume() {
    spotifyPlayer.resume(new Player.OperationCallback() {
        @Override
        public void onSuccess() {
            Log.d(LogTag.LOG_HOST_SERVICE, "Resumed music successfully");
        }

        @Override
        public void onError(Error error) {
            Log.d(LogTag.LOG_HOST_SERVICE, "Failed to resume music");
        }
    });
}
 
开发者ID:ZinoKader,项目名称:SpotiQ,代码行数:14,代码来源:SpotiqHostService.java


示例8: player

import com.spotify.sdk.android.player.Player; //导入依赖的package包/类
public static Player player() {
    return player;
}
 
开发者ID:joxad,项目名称:android-easy-spotify,代码行数:4,代码来源:SpotifyPlayerManager.java


示例9: initPlayer

import com.spotify.sdk.android.player.Player; //导入依赖的package包/类
private Single<Boolean> initPlayer() {
    return Single.create(subscriber -> {

        playerConfig = new Config(SpotiqHostService.this,
            spotifyCommunicatorService.getAuthenticator().getAccessToken(),
            BuildConfig.SPOTIFY_CLIENT_ID);
        playerConfig.useCache(false);

        spotifyPlayer = Spotify.getPlayer(playerConfig, SpotiqHostService.this, new SpotifyPlayer.InitializationObserver() {
            @Override
            public void onInitialized(SpotifyPlayer player) {
                spotifyPlayer.addConnectionStateCallback(SpotiqHostService.this);
                spotifyPlayer.addNotificationCallback(SpotiqHostService.this);
                spotifyPlayer.setPlaybackBitrate(new Player.OperationCallback() {
                    @Override
                    public void onSuccess() {
                        subscriber.onSuccess(true);
                        Log.d(LogTag.LOG_HOST_SERVICE, "Set Spotify Player custom playback bitrate successfully");
                        sendPlayingStatusBroadcast(false); //make sure all listeners are up to sync with an inititally paused status
                        mediaSessionHandler.setSessionActive();
                    }

                    @Override
                    public void onError(Error error) {
                        subscriber.onError(new PlayerInitializationException(error.name()));
                        Log.d(LogTag.LOG_HOST_SERVICE, "Failed to set Spotify Player playback bitrate. Cause: " + error.toString());

                    }
                }, PlaybackBitrate.BITRATE_HIGH);

            }

            @Override
            public void onError(Throwable throwable) {
                subscriber.onError(throwable);
                Log.d(LogTag.LOG_HOST_SERVICE, "Could not initialize Spotify Player: " + throwable.getMessage());
                stopSelf();
            }

        });
    });
}
 
开发者ID:ZinoKader,项目名称:SpotiQ,代码行数:43,代码来源:SpotiqHostService.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AccessTokenResponse类代码示例发布时间:2022-05-23
下一篇:
Java MediaDatabase类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap