Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the Song list in swift code #9

Open
areebvohra opened this issue Jan 9, 2024 · 0 comments
Open

How to get the Song list in swift code #9

areebvohra opened this issue Jan 9, 2024 · 0 comments

Comments

@areebvohra
Copy link

I have seen the media_item.dart file and it seems that the Song class is unfinished. I am trying to get the previewAssets from the Song class.

I need help in extracting the Song list in the swift code.

This is what I have done so far

struct MediaItems: Encodable {
    let title: String?
    let subtitle: String?
    let shazamId: String?
    let appleMusicId: String?
    let appleMusicUrL: URL?
    let artworkUrl: URL?
    let artist: String?
    let matchOffset: TimeInterval?
    let videoUrl: URL?
    let webUrl: URL?
    let genres: [String]
    let isrc: String?
    let url: URL?
}

//MARK: Delegate methods for SHSession
extension SwiftFlutterShazamKitPlugin: SHSessionDelegate{
    public func session(_ session: SHSession, didFind match: SHMatch) {
        let mediaItems = match.mediaItems
        if let firstItem = mediaItems.first {
            let url = firstItem.songs[0].previewAssets?[0].url
            
            let _shazamMedia = MediaItems(
                title:firstItem.title!,
                subtitle:firstItem.subtitle!,
                shazamId:firstItem.shazamID!,
                appleMusicId:firstItem.appleMusicID!,
                appleMusicUrL:firstItem.appleMusicURL!,
                artworkUrl:firstItem.artworkURL!,
                artist:firstItem.artist!,
                matchOffset:firstItem.matchOffset,
                videoUrl:firstItem.videoURL!,
                webUrl:firstItem.webURL!,
                genres:firstItem.genres,
                isrc:firstItem.isrc!,
                url: url!
            )
            
            print("=== _shazamMedia", _shazamMedia)
            
            do {
                let jsonData = try JSONEncoder().encode([_shazamMedia])
                let jsonString = String(data: jsonData, encoding: .utf8)!
                self.callbackChannel?.invokeMethod("matchFound", arguments: jsonString)
            } catch {
                callbackChannel?.invokeMethod("didHasError", arguments: "Error when trying to format data, please try again")
            }
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant