gpt4 book ai didi

android - 有没有办法使用 flutter 链接 Spotify 应用程序上的 Spotify 播放列表?

转载 作者:行者123 更新时间:2023-11-30 04:57:34 25 4
gpt4 key购买 nike

我正在尝试将特定播放列表链接到我的 flutter 应用程序上的按钮。到目前为止,我只能使用 com.spotify.music 打开 Spotify 应用程序。有没有办法在 flutter 上链接播放列表?

最佳答案

您可以使用包 https://pub.dev/packages/spotify
对于播放列表,您可以使用 spotify.playlists.featured.all

代码 fragment

print("\nFeatured Playlist:");
var featuredPlaylists = await spotify.playlists.featured.all();
featuredPlaylists.forEach((playlist) {
print(playlist.name);
});

完整示例代码

// Copyright (c) 2017, rinukkusu. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

import 'dart:io';
import 'dart:convert';
import '../lib/spotify_io.dart';

main() async {
var keyJson = await new File('example/.apikeys').readAsString();
var keyMap = json.decode(keyJson);

var credentials = new SpotifyApiCredentials(keyMap['id'], keyMap['secret']);
var spotify = new SpotifyApi(credentials);

print("Artists:");
var artists = await spotify.artists.list(['0OdUWJ0sBjDrqHygGUXeCF']);
artists.forEach((x) => print(x.name));

print("\nAlbum:");
var album = await spotify.albums.get('2Hog1V8mdTWKhCYqI5paph');
print(album.name);

print("\nAlbum Tracks:");
var tracks = await spotify.albums.getTracks(album.id).all();
tracks.forEach((track) {
print(track.name);
});

print("\nFeatured Playlist:");
var featuredPlaylists = await spotify.playlists.featured.all();
featuredPlaylists.forEach((playlist) {
print(playlist.name);
});

print("\nSearching for \'Metallica\':");
var search = await spotify.search
.get("metallica")
.first(2)
.catchError((err) => print((err as SpotifyException).message));
if (search == null) {
return;
}
search.forEach((pages) {
pages.items.forEach((item) {
if (item is PlaylistSimple) {
print('Playlist: \n'
'id: ${item.id}\n'
'name: ${item.name}:\n'
'collaborative: ${item.collaborative}\n'
'href: ${item.href}\n'
'trackslink: ${item.tracksLink.href}\n'
'owner: ${item.owner}\n'
'public: ${item.owner}\n'
'snapshotId: ${item.snapshotId}\n'
'type: ${item.type}\n'
'uri: ${item.uri}\n'
'images: ${item.images.length}\n'
'-------------------------------');
}
if (item is Artist) {
print('Artist: \n'
'id: ${item.id}\n'
'name: ${item.name}\n'
'href: ${item.href}\n'
'type: ${item.type}\n'
'uri: ${item.uri}\n'
'-------------------------------');
}
if (item is TrackSimple) {
print('Track:\n'
'id: ${item.id}\n'
'name: ${item.name}\n'
'href: ${item.href}\n'
'type: ${item.type}\n'
'uri: ${item.uri}\n'
'isPlayable: ${item.isPlayable}\n'
'artists: ${item.artists.length}\n'
'availableMarkets: ${item.availableMarkets.length}\n'
'discNumber: ${item.discNumber}\n'
'trackNumber: ${item.trackNumber}\n'
'explicit: ${item.explicit}\n'
'-------------------------------');
}
if (item is AlbumSimple) {
print('Album:\n'
'id: ${item.id}\n'
'name: ${item.name}\n'
'href: ${item.href}\n'
'type: ${item.type}\n'
'uri: ${item.uri}\n'
'albumType: ${item.albumType}\n'
'artists: ${item.artists.length}\n'
'availableMarkets: ${item.availableMarkets.length}\n'
'images: ${item.images.length}\n'
'-------------------------------');
}
});
});

var relatedArtists = await spotify.artists.relatedArtists('0OdUWJ0sBjDrqHygGUXeCF');
print('related Artists: ${relatedArtists.length}');
exit(0);
}

关于android - 有没有办法使用 flutter 链接 Spotify 应用程序上的 Spotify 播放列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58868745/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com