- May 29 Tue 2018 13:36
iOS - NShopper (任天堂Switch商城特價遊戲查詢)
- Dec 23 Sat 2017 16:27
iOS - Bitcoin Miner (iOS比特幣挖礦程式)
- Dec 06 Tue 2016 00:41
iOS - Electronic Music Radio (免費電子音樂, 線上廣播)
- Dec 06 Tue 2016 00:35
iOS - Music Addict Radio (免費音樂, 完整曲風, 線上廣播)
- Jun 05 Sun 2016 20:47
iOS - 後搖滾廣播電App(PostRock)
- May 29 Sun 2016 23:56
iOS - 調音器App(ThePitchPerfect)
- Jan 31 Sun 2016 00:01
iOS - FlashSticker(閃亮貼紙)
- Sep 21 Mon 2015 11:02
iOS - 節拍器App(TikTok節拍器 - Metronome)
- Aug 28 Sun 2016 23:54
iOS(Swift) - 播放影片
此篇文播放影片之範例程式, 在storyBoard須先行設定一Button
- Aug 28 Sun 2016 23:30
iOS(Swift) - 播放音樂
此專案為播放音樂之程式, 使用一個label顯示歌曲長度, slider可調整歌曲進度, 最後點擊Btn播放音樂以及停止
import UIKit
import AVFoundation
class ViewController: UIViewController {
@IBOutlet weak var playMusicButtom: UIButton!
@IBOutlet weak var mySlider: UISlider!
@IBOutlet weak var progressTimeLabel: UILabel!
var myPlayer = AVAudioPlayer()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let filePath = NSBundle.mainBundle().pathForResource("ur music in project", ofType: "mp3")
do
{
myPlayer = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: filePath!))
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient)
try AVAudioSession.sharedInstance().setActive(true)
}
catch
{
print("error")
}
NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: #selector(self.playingProgress), userInfo: nil, repeats: true) //每秒更新slider
mySlider.maximumValue = Float(myPlayer.duration) //取得歌曲總長度
}
func playingProgress() //顯示歌曲長度
{
progressTimeLabel.text = String(format: "%.0f/%.0f", myPlayer.currentTime, myPlayer.duration)
mySlider.value = Float(myPlayer.currentTime)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func playMusicButtom(sender: AnyObject) //檢查playBtn之狀態
{
if myPlayer.playing == false
{
myPlayer.play()
playMusicButtom.setTitle("pause", forState: .Normal)
}else{
myPlayer.pause()
playMusicButtom.setTitle("play", forState: .Normal)
}
}
@IBAction func mySlider(sender: AnyObject) //調整slider移動歌曲進度
{
myPlayer.currentTime = Double(mySlider.value)
}
}