This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ "name": "Burj Khalifa", "city": "Dubai", "country": "United Arab Emirates", "height": 828, "yearBuilt": 2010, "latitude": 25.186016587, "longitude": 55.275198221 }, | |
{ "name": "Shanghai Tower", "city": "Shanghai", "country": "China", "height": 632, "yearBuilt": 2015, "latitude": 31.226676271, "longitude": 121.501873778 } | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView: View { | |
@StateObject private var viewModel = HomeViewModel() | |
@Environment(\.openURL) var openURL | |
var body: some View { | |
NavigationView { | |
VStack { | |
List { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ArtworkImage<Content>: View where Content: View { | |
private let url: URL? | |
private var content: (_ image: Image) -> Content | |
public init(url: URL?, @ViewBuilder content: @escaping (_ image: Image) -> Content) { | |
self.url = url | |
self.content = content | |
} | |
var body: some View { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ShazamMusicRow: View { | |
var item: SHMediaItem | |
var body: some View { | |
ZStack { | |
ArtworkImage(url: item.artworkURL) { image in | |
image | |
.scaledToFill() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ShazamMusicCard: View { | |
var item: SHMediaItem | |
var body: some View { | |
HStack { | |
ArtworkImage(url: url) { image in | |
image | |
.scaledToFit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public func addToShazamLibrary() { | |
SHMediaLibrary.default.add(mediaItems) { error in | |
if let error = error { | |
print(error) | |
} else { | |
let generator = UINotificationFeedbackGenerator() | |
generator.notificationOccurred(.success) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK:- SHSessionDelegate | |
extension HomeViewModel: SHSessionDelegate { | |
func session(_ session: SHSession, didFind match: SHMatch) { | |
guard let mediaItem = match.mediaItems.first else { return } | |
async { | |
if mediaItems.contains(where: { $0.shazamID == mediaItem.shazamID }) { | |
// Song already identified and in the list. Do nothing. | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public func startRecognition() { | |
feedback.prepare() | |
// 1 | |
do { | |
if engine.isRunning { | |
stopRecognition() | |
return | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: Audio Recognition | |
extension HomeViewModel { | |
// 1 | |
private func prepareAudioRecording() throws { | |
let audioSession = AVAudioSession.sharedInstance() | |
try audioSession.setCategory(.record) | |
try audioSession.setActive(true, options: .notifyOthersOnDeactivation) | |
} |
NewerOlder