Last active
February 22, 2017 05:02
-
-
Save AtharvaVaidya/0de719e8c9407d7ffb2d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// | |
// SMetadata.swift | |
// SimpleMusic | |
// | |
// Created by Atharva Vaidya on 09/08/15. | |
// Copyright (c) 2015 Atharva Vaidya. All rights reserved. | |
// | |
import Cocoa | |
import AVFoundation | |
class SMetadata: AVMetadataItem | |
{ | |
var title: String! | |
var artist: String! | |
var album: String! | |
func metaDataForAVAsset(asset: AVAsset) -> [String:String] | |
{ | |
//Updated code thanks to the fork from istx25 on GitHub | |
var metadata = ["title": "", "artist": "", "albums": ""] | |
let metaTitle = AVMetadataItem.metadataItemsFromArray(asset.commonMetadata, withKey: AVMetadataCommonKeyTitle, keySpace: AVMetadataKeySpaceCommon) | |
let titles = metaTitle.first! as! AVMetadataItem | |
title = "\(titles.value())" | |
metadata["title"] = title | |
let metaArtist = AVMetadataItem.metadataItemsFromArray(asset.commonMetadata, withKey: AVMetadataCommonKeyArtist, keySpace: AVMetadataKeySpaceCommon) | |
let artists = metaArtist.first! as! AVMetadataItem | |
artist = "\(artists.value())" | |
metadata["artist"] = artist | |
let metaAlbum = AVMetadataItem.metadataItemsFromArray(asset.commonMetadata, withKey: AVMetadataCommonKeyAlbumName, keySpace: AVMetadataKeySpaceCommon) | |
let albums = metaAlbum.first! as! AVMetadataItem | |
album = "\(albums.value())" | |
metadata["album"] = album | |
return metadata | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot for the advice, I'm still a beginner.
The strange thing is I already knew points 1 and 3, but for some reason my brain didn't think to write the code in that way. Oh well, now I'll remember to do those things because they'll stick in my memory.