Skip to content

Instantly share code, notes, and snippets.

Avatar
🎧
Hustling

Rudrank Riyam rudrankriyam

🎧
Hustling
View GitHub Profile
View tallesttowers.json
[
{ "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 }
]
View ContentView.swift
import SwiftUI
struct ContentView: View {
@StateObject private var viewModel = HomeViewModel()
@Environment(\.openURL) var openURL
var body: some View {
NavigationView {
VStack {
List {
View HomeButtonsView.swift
extension Image {
func imageButton(with size: CGFloat, color: Color) -> some View {
self
.resizable()
.scaledToFit()
.frame(width: size, height: size)
.foregroundColor(color)
}
}
View ArtworkImage.swift
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 {
View ShazamMusicRow.swift
import SwiftUI
struct ShazamMusicRow: View {
var item: SHMediaItem
var body: some View {
ZStack {
ArtworkImage(url: item.artworkURL) { image in
image
.scaledToFill()
View ShazamMusicCard.swift
import SwiftUI
struct ShazamMusicCard: View {
var item: SHMediaItem
var body: some View {
HStack {
ArtworkImage(url: url) { image in
image
.scaledToFit()
@rudrankriyam
rudrankriyam / HomeViewModel.swift
Created Sep 13, 2021
HomeViewModel addToShazamLibrary
View HomeViewModel.swift
public func addToShazamLibrary() {
SHMediaLibrary.default.add(mediaItems) { error in
if let error = error {
print(error)
} else {
let generator = UINotificationFeedbackGenerator()
generator.notificationOccurred(.success)
}
}
}
@rudrankriyam
rudrankriyam / HomeViewModel.swift
Created Sep 13, 2021
HomeViewModel + SHSessionDelegate
View HomeViewModel.swift
// 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 {
@rudrankriyam
rudrankriyam / HomeViewModel.swift
Created Sep 13, 2021
HomeViewModel recognition
View HomeViewModel.swift
public func startRecognition() {
feedback.prepare()
// 1
do {
if engine.isRunning {
stopRecognition()
return
}
@rudrankriyam
rudrankriyam / HomeViewModel.swift
Created Sep 13, 2021
HomeViewModel extension ShazamKit
View HomeViewModel.swift
// MARK: Audio Recognition
extension HomeViewModel {
// 1
private func prepareAudioRecording() throws {
let audioSession = AVAudioSession.sharedInstance()
try audioSession.setCategory(.record)
try audioSession.setActive(true, options: .notifyOthersOnDeactivation)
}