Skip to content

🎧 Music application with UIKit & SwiftUI. Uses iTunes Search API. Almost like Apple Music. Made with Clean Swift(VIP) architecture.

Notifications You must be signed in to change notification settings

bgoncharov/iMusic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

iMusic

Music application that uses iTunes Search API. Almost like Apple Music. Made with Clean Swift(VIP) architecture.

Stack: iTunes Search API, UIKit, SwiftUI, AVKit, URLImage, SDWebImage, Clean Swift(VIP).

Demo Demo

Сontents

Setup application in code

MainTabBarController file

override func viewDidLoad() {
        super.viewDidLoad()
        
        searchVC.tabBardelegate = self
        
        var library = Library()
        library.tabBarDelegate = self
        let hostVC = UIHostingController(rootView: library)
        hostVC.tabBarItem.image = #imageLiteral(resourceName: "library")
        hostVC.tabBarItem.title = "Library"

        viewControllers = [
            hostVC, 
            generateViewController(rootViewController: searchVC, image: "magnifyingglass", title: "Search")
        ]
    }

UIKit and SwiftUI

There are two main screens: Search and Library. Search screen made with UIKit, and Library made with SwiftUI. To make work them together in func viewDidLoad() of MainTabBarController (which is main controller for both views) I used UIHostingController().

var library = Library()
library.tabBarDelegate = self
let hostVC = UIHostingController(rootView: library)

Player

TrackDetailView file

Track player made with AVKit

let player: AVPlayer = {
        let avPlayer = AVPlayer()
        avPlayer.automaticallyWaitsToMinimizeStalling = false
        return avPlayer
 }()

func awakeFromNib() anstead of func viewDidLoad(), because TrackDetailView representation made with xib file.

override func awakeFromNib() {
        super.awakeFromNib()
}

Gestures

private func setupGestures() {
        
        miniTrackView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(handleTapMaximized)))
        miniTrackView.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(handlePan)))
        addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(handleDismissalPan)))
 }

Animation

If you press play or pause you'll see that track image changes size with animation.

private func enlargeTrackImageView() {
    UIView.animate(withDuration: 1, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 1, options: .curveEaseInOut, animations: {
       self.trackImageView.transform = .identity
     }, completion: nil)
}
    
private func reduceTrackImageView() {
   UIView.animate(withDuration: 1, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 1, options: .curveEaseInOut, animations: {
     let scale: CGFloat = 0.8
     self.trackImageView.transform = CGAffineTransform(scaleX: scale, y: scale)
    }, completion: nil)
}

Images and SDWebImage Library

SDWebImage provides an async image downloader with cache support.

miniTrackImageView.sd_setImage(with: url, completed: nil)
trackImageView.sd_setImage(with: url, completed: nil)

About

🎧 Music application with UIKit & SwiftUI. Uses iTunes Search API. Almost like Apple Music. Made with Clean Swift(VIP) architecture.

Resources

Stars

Watchers

Forks