我正在尝试使用 Deezer Android API 播放音乐,遵循 SDK 的示例代码。我只得到 30 年代的预览,从来没有流。以下是返回的输出片段:
{"id":"72306644","readable":true,"title":"Aura","link":"http:\/\/www.deezer.com\/track\/72306644","duration":236,"track_position":1,"disk_number":1,"rank":426293,"preview":"http:\/\/cdn-preview-e.deezer.com\/stream\/e0c84057c93e3cad84317d768413c0e3-0.mp3","stream":false,"artist"
{"id":"75491","name":"Lady GaGa","type":"artist"},"type":"track"}
认证成功。我使用高级 + 帐户登录。我做错了什么或错过了一步吗?
它现在似乎正在返回流 - 也许只是需要时间将帐户升级到高级+。然而,它没有播放流。即没有播放音乐。
它非常接近 SDK 中的示例代码并基于在线文档:首先创建播放器:
deezerConnect = new DeezerConnectImpl( parentActivity, APP_ID );
try {
player = new DefaultPlayerFactory( parentActivity.getApplication(),
deezerConnect, new WifiOnlyNetworkStateChecker() ).createPlayer();
} catch (Exception e) {
handleError( e );
}
然后打个电话去听歌...
private void searchTracks(Album album) {
long albumId = album.getId();
Bundle bundle = new Bundle();
bundle.putString( "nb_items", "30");
DeezerRequest request = new DeezerRequest( "album/"+albumId+"/tracks", bundle );
request.setId( String.valueOf( albumId ) );
deezerConnect.requestAsync( request, trackHandler );
}
然后在 trackHandler 中解析结果并使用 gson 创建一个轨道对象后,它会尝试播放轨道:
private void playTrack( Track track ) {
if( player.getPlayerState() != PlayerState.STARTED ) {
player.stop();
}//if
Log.d(TAGNAME, "Init track:" + track.getId() +":"+ deezerConnect.getAccessToken() +":"+
track.getStream() );
if( track.hasStream() ) {
player.init( track.getId(), track.getStream());
} else {
Log.d( TAGNAME,"Playing track preview:" + track.getId() );
player.init( track.getId(), track.getPreview() );
}//else
player.setPlayerProgressInterval(1000);
player.play();
}
如果有帮助,以下是响应输出的一些片段:
响应:{"data":[{"id":"17519569","可读":true,"title":"Dirty Paws","link":"http://www.deezer.com/track/17519569 ","duration":278,"track_position":1,"disk_number":1,"rank":399040,"preview":"http://cdn-preview-d.deezer.com/stream/def7161be8ee42ecb20036a136ad0cf6-2 .mp3","stream":" ....这里的十六进制数字长字符串... ","artist":{"id":"1581786","name":"Of Monsters And Men","type ":"艺术家"},"类型":"曲目"}