Thursday, August 20, 2015
iOS application development
Creating an application can be a daunting yet easy task. For example how do you add, play and stop audio?
Below is a sample switch code you could use for this function:
//
//  PlaySoundsViewController.swift
//  SoundRecording
//
//  Created by Jackson on 8/20/15.
//  Copyright (c) 2015 yosohotech. All rights reserved.
//
import UIKit
import AVFoundation
class PlaySoundsViewController: UIViewController {
    var audioPlayer:AVAudioPlayer!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        if var filePath = NSBundle.mainBundle().pathForResource("movie_quote", ofType: "mp3"){
            var filePathurl = NSURL.fileURLWithPath(filePath)
            audioPlayer = AVAudioPlayer(contentsOfURL: filePathurl, error: nil)
            audioPlayer.enableRate = true
            
        } else{
            println("the filepath is empty")
        }
    }
    
        
    @IBAction func playSlowAudio(sender: UIButton) {
        //Play audio slooowly here.....
        audioPlayer.stop()
        audioPlayer.rate = 0.2
        audioPlayer.currentTime = 0.0
        audioPlayer.play()
        
    }
    
    @IBAction func playFastAudio(sender: UIButton) {
        //Play fast audio here...
        audioPlayer.stop()
        audioPlayer.rate = 2.0
        audioPlayer.currentTime = 0.0
        audioPlayer.play()
    }
    @IBAction func stopPlayingMusic(sender: UIButton) {
        //Stop playing audio file here...
        audioPlayer.stop()
        
    }
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
}
    /*
    // MARK: - Navigation
    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */
}
http://www.mendeley.com/research/udacity-21st-century-university/
Subscribe to:
Post Comments (Atom)
 
No comments:
Post a Comment