Machineboy空
MusicKit은 어떤 기능들을 제공하고 있는가.. 본문
MusicKit은 WWDC2017에서 공개된 새로운 프레임 워크다.
(Set of client frameworks and Apple Music API)
Apple Music과 연동되는 앱을 쉽게 만들 수 있다.
워낙 MusicKit 예제가 드물어서 (사실 많이 찾아본 건 아니다만)
공인된 WWDC영상을 보는 것이 정석적인 공부 방식이다..
IT쪽은 워낙 신기술이 많이 등장하기도 하고, 정보 공유(?)가 하나의 문화인 곳이다 보니
이런 개발자 컨퍼런스 영상들과, 공식 문서들과 친해져야 함을 요새 깨닫고 있다.
영상 보는 순서는 이러하다.
1. [WWDC21] Meet MusicKit for Swift (참고, WWDC에서 Meet 시리즈가 가장 개요인 느낌)
https://developer.apple.com/wwdc21/10294
2. [WWDC21] Explore the catalog with the Apple Music API
https://developer.apple.com/wwdc21/10291
3. [WWDC22] Meet Apple Music API and MusicKit
https://developer.apple.com/wwdc22/10148
4. [WWDC22] Explore more content with MusicKit
https://developer.apple.com/wwdc22/110347
그래도 이렇게 공식으로 제공하는 영상들이 있으니 얼마나 친절한가 싶기도 하고
예전에 리듬게임 만들 때, DRYWETMIDI나 다른 라이브러리들 찾아 공부하고,
다른 튜토리얼이 없어 직접 디버깅 하며 소리별 수치 비교하며 구조를 분석하던 것과 비교하면 훨씬 편한 것 같기도 하다.
그래서 내가 MusicKit과 AppleMusicAPI를 활용해 구현해야 하는 기능은?
- 음악(아티스트명, 노래명 등)을 검색 시, 연관 검색어가 뜨도록 searchResponse.topResults
- 최근에 들었던 곡 기반 리스트 띄우기 MusicRecentlyPlayedContainerRequest()
- 선택한 곡 재생하기 ApplicationMusicPlayer
- 플레이어 기능 (버튼 별 일시정지, 이전곡, 다음곡 등) + 위젯 ApplicationMusicPlayer
- 다음곡 눌렀을 때, 현재곡 기반으로 추천된 음악으로 넘어가기 MusicPersonalRecommendationsRequest()
- 다음에 들어올 곡들 리스트 띄우기 MusicPersonalRecommendationsRequest()
정확히 이 기능들이 해당 역할들을 수행하는진 모르겠지만, 연관성이 있어보이는 것으로 우선 적어두고 수정해보겠다.
# 뮤직킷 기본 정보
# 검색창 관련
1. Top Result / Suggestions
When typing to search for content, you may want to provide strong, music-related auto-complete support.
That's where suggestions come into play, providing terms that people may be trying to reach.
You can even take it a step further and display top results for quick access to what people may be searching for.
//top Result
var searchRequest = MusicCatalogSearchRequest{
term: "jack harl",
types: [
Artist.self,
Album.self,
Song.self
]
searchRequest.includeTopResults = true
let searchResponse = try await searchRequest.response()
print("\(searchResponse)")
}
// Loading suggestions
let request = MusicCatalogSearchSuggestionsRequest(terms: "jack harl")
let response = try await request.response()
print("\(response)")
# 개인화된 콘텐츠 관련(Fetching personalized content)
1. Curator / Radio Show 기능
We can easily find all of the playlists generated by this curator.
This functionality allows people to get quick access to playlists they may love, finding new songs or revisiting old favorites.
Radio show is another way to discover new music through seasoned professionals.
직접 한번 사용해보고 무슨 기능인지 알아내보겠음..
2.Fetching personalized content (Recently played items, Personal recommendations)
providing a unique and tailored experience for every user in your app.
Normally, personalized content requires special authentications and user tokens, but in the MusicKit framework, we've made this all automatic so you don't have to deal with any of the hassle.
- Recently played items
//Loading recently played containers
let request = MusicRequestPlayedContainerRequest(<Song>)
let response = try await request.response()
print("\(response)")
- Personal recommendations
- Based on user's library and listening history
- Organized by themes (genre, artist, collection에 따라 그룹화)
3. Exploring the library
- Fetching items
- Library requests
- Library sectioned request
- Library search
- Enhancements to load additional properties
뮤직 마라톤이라는 앱 예시, 애플 뮤직 앱이랑 번걸아 켜지 않고 이 앱을 통해 직접적인 음악 재생이 가능해졌다.
struct LibraryView: View{
private var librarySearchView: some View{
}
@ViewBuilder
private var libraryPlaylists: some View {
if viewModel.searchResponse != nil {
librarySearchView
}else if let response = response {
List {
Section(header: Text("Library Playlists").fontweight(.semibold)) {
ForEach(response.items) { playlist in
PlaylistCell(playlist)
}
}
}
}
}
@MainActor
private func loadLibraryPlaylists() async throws {
let request = MusicLibraryRequest<Playlist>()
let response = try await request.response()
self.response = response
}
}
MusicLibraryRequest는 장치에 저장된 Generic over type of item, filter by specific properties, Built-in sorting options, Fetch already downloaded item에 접근할 수 있고
요청문에 여러 필터를 적용해 옵션을 분류할 수 있다.
// Fetching all complications in the library
var request = MusicLibraryRequest<Album>()
request.filter(matching: \.isCompliation, equalTo: true)
request.filter(matching: \.genres, contatins: danceGenre)
request.includeDownloadContentOnly = true
let response = try await request.response()
print("\(response)")