ZLMusic模仿百度音乐应用项目源码-创新互联-成都快上网建站

ZLMusic模仿百度音乐应用项目源码-创新互联

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 p_w_picpath = UIImage(data: data)
            self.songImageView.p_w_picpath = p_w_picpath
        }
        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开发的百度音乐电台,基本模仿了现实中的百度音乐应用功能了,支持播放功能,上首歌,下一首个,以及歌曲分类等。

为襄城等地区用户提供了全套网页设计制作服务,及襄城网站建设行业解决方案。主营业务为成都网站建设、成都做网站、襄城网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

项目×××:http://code.662p.com/view/9375.html

  • ZLMusic模仿百度音乐应用项目源码

    运行截图

  • ZLMusic模仿百度音乐应用项目源码

    运行截图

  • ZLMusic模仿百度音乐应用项目源码

    运行截图

  • 详细说明:http://ios.662p.com/thread-2239-1-1.html

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


文章题目:ZLMusic模仿百度音乐应用项目源码-创新互联
当前路径:http://kswjz.com/article/pgjcs.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流