搜尋套件、儲存庫與 APP 分類

套件詳情v0.3.5+6

flutter_audio_query

Flutter 插件,用於從裝置儲存中查詢有關藝術家、專輯、歌曲、類型和播放列表的資料。

近 30 天下載
24
喜歡數
94
Pub 分數
40

安裝套件

flutter pub add flutter_audio_query

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

Flutter Audio Query 是一個 Flutter 插件,讓開發者能夠存取並取得裝置儲存空間中的媒體元資料,包含藝術家、專輯、歌曲、類型與播放清單等資訊。它提供簡單的 API 來查詢裝置的音樂庫,非常適合用於建構音樂播放器應用程式或媒體管理工具。此外,該插件支援跨平台使用,雖然各平台的支援程度可能略有不同。它能簡化與原生音訊資料來源的整合,無需撰寫複雜的原生程式碼。

適用情境

  • 建構音樂播放器應用
  • 建立媒體庫介面
  • 獲取歌曲元數據
  • 顯示藝術家和專輯詳細資訊
  • 管理用戶播放列表

主要特色

  • 訪問設備音樂庫
  • 支援藝術家、專輯、歌曲、流派、播放列表
  • 簡單且一致的 API
  • 跨平台相容性
  • 高效數據檢索

適合對象

  • 音樂應用開發者
  • 媒體庫建構器
  • 音頻內容管理員
  • Flutter 初學者探索媒體功能
  • 需要離線音樂元資料的應用

使用建議

  • 平台特定的限制可能適用
  • 需要在 Android 和 iOS 上具備適當的權限
  • 僅限設備儲存的媒體
  • 媒體更改無即時更新
  • 取決於設備媒體資料庫的一致性

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Flutter Audio Query

A Flutter plugin, Android only at this moment, that allows you query for audio metadata info about artists, albums, songs audio files and genres available on device storage. All work is made using Android native MediaStore API with ContentResolver API and query methods run in background thread. AndroidX support it's OK!

Note: This plugin is under development, Works in Android devices only and some APIs are not available yet. Feedback, pull request, bug reports and suggestions are all welcome!

Feel free to help!

Example app included

| | | |

Features

  • Android permissions READ_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE built-in
  • Get all artists audio info available on device storage
  • Get artists available from a specific genre
  • Search for artists matching a name
  • Artist comes with some album Artwork cover if available
  • Get all albums info available on device storage
  • Get albums available from a specific artist
  • Get albums available from a specific genre
  • Search albums matching a name
  • Album artwork included if available
  • Get songs all songs available on device storage
  • Get songs from a specific album
  • Songs already comes with album artwork cover if available
  • Get availables genre.
  • Get all playlists available
  • Create new playlists
  • Remove playlist
  • Add songs to playlist
  • Remove song from playlist
  • Multiple sort types for Artist, Album, Song, Genre, Playlist.

TO DO

  • Make this basic implementation for iOS.
  • Allow change playlist songs order
  • Streams support.
  • Improvements in background tasks.
  • More tests and probably bug fixes.

Usage

To use this plugin, add flutter_audio_query as a dependency in your pubspec.yaml file. For example:

  dependencies:
    flutter_audio_query: "^0.3.5+6"

API

FlutterAudioQuery

To get get audio files metadata info you just need FlutterAudioQuery object instance.

///you need include this file only.
import 'package:flutter_audio_query/flutter_audio_query.dart';
/// create a FlutterAudioQuery instance.
final FlutterAudioQuery audioQuery = FlutterAudioQuery();
Getting all artist available on device storage:
List<ArtistInfo> artists = await audioQuery.getArtists(); // returns all artists available

artists.forEach( (artist){
      print(artist); /// prints all artist property values
    } );
Getting albums data:
 /// getting all albums available on device storage
 List<AlbumInfo> albumList = await audioQuery.getAlbums();

/// getting all albums available from a specific artist
List<AlbumInfo> albums = await audioQuery.getAlbumsFromArtist(artist: artist.name);
    albums.forEach( (artistAlbum) {
      print(artistAlbum); //print all album property values
    });
Getting artwork on Android >= Q:

Since Android API level 29 ALBUM_ART constant is deprecated and plus scoped storage approach we can't load artwork from absolute image path. So if your app is running over Android API >= 29 you will get all artwork fields with null. To fetch images on these API levels you can use getArwork method.

 /// detecting, loading and displaying an artist artwork.
 
 ArtistInfo artist // assuming a non null instance

 // check if artistArtPath isn't available.

 (artist.artistArtPath == null)

    ? FutureBuilder<Uint8List>(
      future: audioQuery.getArtwork(

        type: ResourceType.ARTIST, id: artist.id),
        builder: (_, snapshot) {
          if (snapshot.data == null)
            return Container(
              height: 250.0,
              child: Center(
                child: CircularProgressIndicator(),
              ),
            );
            
            return CardItemWidget(
              height: 250.0,
              title: artist.name,
              subtitle: "Number of Albums: ${artist.numberOfAlbums}",
              infoText: "Number of Songs: ${artist.numberOfTracks}",
              // The image bytes
              // You can use Image.memory widget constructor 
              // or MemoryImage image provider class to load image from bytes
              // or a different approach.
              rawImage: snapshot.data,
            );
          }) :
          // or you can load image from File path if available.
          Image.file( File( artist.artistArtPath ) )

Getting genre data
/// getting all genres available
 List<GenreInfo> genreList = audioQuery.getGenres();

 genreList.foreach( (genre){
   /// getting all artists available from specific genre.
   await audioQuery.getArtistsFromGenre(genre: genre.name);

   /// getting all albums which appears on genre [genre].
   await audioQuery.getAlbumsFromGenre(genre: genre.name);

   /// getting all songs which appears on genre [genre]
   await audioQuery.getSongsFromGenre(genre: genre.name);
 } );
Getting songs data
/// getting all songs available on device storage
List<SongInfo> songs = await audioQuery.getSongs();

albumList.foreach( (album){
 /// getting songs from specific album
 audioQuery.getSongsFromAlbum(album: album.name);
} );
Getting playlist data
    /// getting all playlist available
    List<PlaylistInfo> playlist = await audioQuery.getPlaylists();

    /// Getting playlist songs
    List<SongInfo> songs = await audioQuery.getSongsFromPlaylist(playlist: playlist[0]);

    /// adding songs into a specific playlist
    PlaylistInfo updatedPlaylist = await playlist[0].addSong(song: songs[2] );

    //removing song from a specific playlist
    updatedPlaylist = await updatedPlaylist.removeSong(song: songs[2]);
Sorting queries

You can also define a sort query constraint to get the data already sorted using sort enums.ArtistSortType, AlbumSortType, SongSortType, GenreSortType, PlaylistSortType.

    /// Getting albums sorted by most recent year first
    audioQuery.getAlbums(sortType: AlbumSortType.MOST_RECENT_YEAR )

    /// getting artists sorted by number of songs
    audioQuery.getArtits(sortType: ArtistSortType.MORE_TRACKS_NUMBER_FIRST);
    /// and more...
Searching

You can search using search methods.

    ///searching for albums that title starts with 'a'
    List<AlbumInfo> albums = await audioQuery.searchAlbums(query "a");

    /// searching for songs that title starts with 'la'
    List<SongInfo> songs = await audioQuery.searchSongs(query: "la");

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT LICENSE

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。