ZLMusic imitates the source code of the Baidu music application project and zlmusic Baidu music

Source: Internet
Author: User

ZLMusic imitates the source code of the Baidu music application project and zlmusic Baidu music

 

Func stopPlayMusic () {if (self. isStop = true) {self. player. pause () btn. setTitle ("play", forState: UIControlState. normal) // var paused = player. currentTime self. songImageView. layer. speed = 0.0} else {self. player. play () btn. setTitle ("pause", forState: UIControlState. normal) self. songImageView. layer. beginTime = player. currentTime self. songImageView. layer. speed = 0.1} isStop =! IsStop} func downloadData (path: NSString, dataHandler: (NSData)-> Void) {var url = NSURL (string: path) var request = NSURLRequest (URL: url) var mainQueue = NSOperationQueue. mainQueue () NSURLConnection. sendAsynchronousRequest (request, queue: mainQueue) {(response: NSURLResponse !, Data: NSData !, Error: NSError !) -> Void in var httpResponse = response as NSHTTPURLResponse if httpResponse. statusCode = 200 {dataHandler (data) }}func downloadSong (path: NSString) {self. downloadData (path, dataHandler: {(data: NSData)-> Void in self. playSong (data)} func downloadSongLrc (path: NSString) {var lrcPath = "http://ting.baidu.com \ (path)" self. downloadData (lrcPath, dataHandler: {(data: NSData)-> Void in va R lrc = NSString (data: data, encoding: NSUTF8StringEncoding) var lrcLists = lrc. componentsSeparatedByString ("\ n") as NSArray println ("\ (lrc)") println ("\ (lrcLists [5])} func loadSongMessage (id: Int) {var path = "http://music.baidu.com/data/music/fmlink? Type = mp3 & rate = 1 & format = json & songIds = \ (id) "downloadData (path, dataHandler: {(data: NSData)-> Void in var array: NSDictionary = NSJSONSerialization. JSONObjectWithData (data, options: NSJSONReadingOptions. allowFragments, error: nil) as NSDictionary var dataDic: NSDictionary = array ["data"] as NSDictionary var list: NSArray = dataDic ["songList"] as NSArray var songDic: NSDictionary = list [0] as NSDictio Nary self. currentSong. refreshSong (songDic) self. title = self. currentSong. songName println ("\ (songDic)") self. playImage (self. currentSong. songPicRadio) self. showSongInfo () self. downloadSong (self. currentSong. songLink) self. downloadSongLrc (self. currentSong. lrcLink)} func playImage (path: NSString) {if path = "" {self. songImageView. backgroundColor = UIColor. cyanColor ()} else {var url = NSURL (stri Ng: path) var data = NSData (contentsOfURL: url, options: nil, error: nil) var image = UIImage (data: data) self. songImageView. image = image} self. songImageView. contentMode = UIViewContentMode. scaleAspectFit self. songImageView. layer. cornerRadius = self. songImageView. frame. width/2 self. songImageView. layer. masksToBounds = true self. songImageView. userInteractionEnabled = true var ges = UITapGestureRec Ognizer (target: self, action: "tapImageView:") self. songImageView. addGestureRecognizer (ges)} func showSongInfo () {self. artistName. text = self. currentSong. artistName self. songName. text = self. currentSong. songName self. timeLabel. text = "00:00"} func loadSongList () {var path = "http://fm.baidu.com/dev/api? Tn = playlist & special = flash & prepend = & format = json & _= 1378945264366 & id = "+ String (channel. id) downloadData (path, dataHandler: {(data: NSData)-> Void in var dic: NSDictionary = NSJSONSerialization. JSONObjectWithData (data, options: NSJSONReadingOptions. allowFragments, error: nil) as NSDictionary var list: NSArray = dic ["list"] as NSArray for dict in list {var song = Song () song. id = dict ["id"] as Int self. SongList. append (song)} if self. songList. count! = 0 {self. currentSong = self. songList [0] self. loadSongMessage (self. currentSong. id) }})} func doAnimation () {var animation = CABasicAnimation (keyPath: "transform. rotation. z ") animation. toValue = NSNumber (double: 2.0 * M_PI) animation. duration = 1.5 animation. timingFunction = CAMediaTimingFunction (name: kCAMediaTimingFunctionLinear) animation. removedOnCompletion = false animation. cumulative = false Animation. repeatCount = FLT_MAX self. songImageView. layer. addAnimation (animation, forKey: "AnimatedKey") self. songImageView. layer. speed = 0.1} func tapImageView (sender: UITapGestureRecognizer) {self. stopPlayMusic ()} override func viewDidLoad () {super. viewDidLoad () // self. title = channel. title loadSongList () self. view. backgroundColor = UIColor (red: 218/255. 0, green: 225/255. 0, blue: 230/255. 0, al Pha: 1) println ("\ (channel. id) ")} override func viewWillDisappear (animated: Bool) {timer. invalidate () self. songImageView. stopAnimating () player. stop ()} override func didReceiveMemoryWarning () {super. didReceiveMemoryWarning () // Dispose of any resources that can be recreated .} func AudioPlayerDidFinishPlaying (player: AVAudioPlayer !, Successfully flag: Bool) {timer. invalidate () self. songImageView. layer. speed = 0 self. songImageView. stopAnimating () var index = self. currentIndex + 1 loadSongWithIndex (index )}



 

This project is a good ZLMusic app that imitates Baidu music and uses Baidu music radio station developed by Swift. It basically imitates the functions of Baidu music app in reality. It supports the playback function and adds a song, the next one, as well as the category of songs.

Project source code download: http://code.662p.com/view/9375.html

    • <Ignore_js_op> RUN
    • <Ignore_js_op> RUN
    • <Ignore_js_op> RUN
    • Http://ios.662p.com/thread-2239-1-1.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.