国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設(shè)計 > 正文

ZLMusic模仿百度音樂應用項目源碼

2019-11-14 19:34:30
字體:
供稿:網(wǎng)友

 

func stopPlayMusic() {    if (self.isStop == true) {        self.player.pause()        btn .setTitle("播放", forState:UIControlState.Normal)        //var paused = player.currentTime        self.songImageView.layer.speed = 0.0             }else{        self.player.play()        btn .setTitle("暫停", 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            var 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 NSDictionary            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(string: 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 = UITapGestureRecognizer(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, alpha: 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)}



 

這個項目是一個比較不錯的ZLMusic模仿百度音樂應用,也是采用Swift開發(fā)的百度音樂電臺,基本模仿了現(xiàn)實中的百度音樂應用功能了,支持播放功能,上首歌,下一首個,以及歌曲分類等。

項目源碼下載:http://code.662p.com/view/9375.html


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 丹巴县| 海丰县| 焉耆| 舒城县| 岳池县| 合肥市| 当涂县| 惠安县| 鹤壁市| 沐川县| 道孚县| 宜城市| 栾川县| 高邮市| 滨州市| 阿拉善左旗| 龙山县| 察隅县| 平陆县| 广南县| 辽阳县| 乾安县| 吉安市| 都匀市| 景宁| 西贡区| 嘉定区| 谷城县| 金门县| 东城区| 白朗县| 油尖旺区| 腾冲县| 庆元县| 西安市| 河北省| 河北省| 新宾| 祁门县| 兖州市| 于田县|