Skip to content

Instantly share code, notes, and snippets.

View rudrankriyam's full-sized avatar
🎵
Living.

Rudrank Riyam rudrankriyam

🎵
Living.
View GitHub Profile
@rudrankriyam
rudrankriyam / AnimatedMeshView.swift
Created June 12, 2024 22:54
Creating animated music background using SwiftUI's new MeshGradient
//
// AnimatedMeshView.swift
// Fussion
//
// Created by Rudrank Riyam on 11/06/24.
//
import Foundation
import MusicKit
import ColorKit
[
{ "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 }
]
@rudrankriyam
rudrankriyam / ContentView.swift
Created September 13, 2021 23:12
ContentView
import SwiftUI
struct ContentView: View {
@StateObject private var viewModel = HomeViewModel()
@Environment(\.openURL) var openURL
var body: some View {
NavigationView {
VStack {
List {
@rudrankriyam
rudrankriyam / HomeButtonsView.swift
Created September 13, 2021 23:12
HomeButtonsView
extension Image {
func imageButton(with size: CGFloat, color: Color) -> some View {
self
.resizable()
.scaledToFit()
.frame(width: size, height: size)
.foregroundColor(color)
}
}
@rudrankriyam
rudrankriyam / ArtworkImage.swift
Created September 13, 2021 23:11
ArtworkImage
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 {
@rudrankriyam
rudrankriyam / ShazamMusicRow.swift
Created September 13, 2021 23:10
ShazamMusicRow
import SwiftUI
struct ShazamMusicRow: View {
var item: SHMediaItem
var body: some View {
ZStack {
ArtworkImage(url: item.artworkURL) { image in
image
.scaledToFill()
@rudrankriyam
rudrankriyam / ShazamMusicCard.swift
Created September 13, 2021 23:09
ShazamMusicCard
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 September 13, 2021 23:08
HomeViewModel addToShazamLibrary
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 September 13, 2021 23:07
HomeViewModel + SHSessionDelegate
// 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 September 13, 2021 23:06
HomeViewModel recognition
public func startRecognition() {
feedback.prepare()
// 1
do {
if engine.isRunning {
stopRecognition()
return
}