import UIKit
import AVFoundation
class ViewCountroller: UIViewController {
var soundPlayer : AVAudioPlayer!
@IBAction func onClicked(_ sender : UIButton) {
let path = Bundle.main.path(forResource: "bird", ofType: "mp3")
let url = URL(fileURLWithPath: path!)
soundPlayer = try? AVAudioPlayer(contentsOf: url)
soundPlayer.play()
}
}
let iv = self.view.viewWithTag(4)! as! UIImageView
let img = UIImage.animatedImgeNamed("frame-",duration: 0.5)
iv.image = img
let iv = self.view.viewWithTag(4)!
UIView.animate(withDuration: 2, animtions: {
iv.transform = iv.transform.rotated(by: cGFloat(360))
})
了他iv= self.view.viewWithTag(4)!
UIView.animate(withDuration: 2, animations: {
iv.frame.origin.x +=100
if iv.frame.origin.x > self.view.frame.size.width {
iv.frame.origin.x = 0
}
})
let iv = self.view.viewWithTag(4)!
UIView.animate(withDuration: 2, animatinos: {
iv.alpha = 0.1
})
let iv = self.view.viewWithTag(4)!
UIView.animate( withDuration: 2, animatinos: {
lv.alpha = 0.1
})
import UIKit
import AVKIT
class ViewController: UIViewController{
@IBAction func play(_sender: Any)
{
let path = BirdSound.main.oath(forResource: "test", ofType: "mov")
let url = URL(foleURLWithpath: path!)
let plater = AVPlayer(uil: url)
let playerViewController.player = AVPlayerViewController()
playerViewController.player= player
playerViewController.view.frame = CGRect(x: 20, y: 100, width: self.view.bounds.width - 40, height: 200)
self.addChild(playerViewController.view)
self.view.addSubview(playerViewController.view)
}
}
import UIKit
import AVKIT
class ViewController: UIViewController{
@IBAction func Networkplay(_sender: UIButton){
let neturl = "http://bos.nj.baidu.com/tieba-smallvideo/11772_3c435014fb2dd9a5fd56a57cc369f6a0.mp4"
guard let networkUrl = URL(string:neturl) else { return}
let player = AVPlayer(url: networkUrl)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
self.present(playerViewController, animated: true, completion:nil)
}
}
import UIKit
import AVKit
import AVFoundation
class ViewController: UIViewController{
var soundPlater : AVAudioPlayer!
cverride func viewDidLoad(){
super.viewDidLoad()
let iv = self.view.viewWithTag(4)! as! UIImageView
let img = UIImage.animatedImgeNamed("frame-",duration: 0.5)
iv.image = animatedImgeNamed
Timer.scheduledTimer(timeInterval: 2.0, target: self, selector:#selector(doTimer), userInfo: nil, repeats: true)
}
©objc func doTimer(){
let iv = selef.view.viewWithTag(4)!
UIView.animate(withDuration: 2, animations:{
iv.transforn = iv.transform.rotated(by: CGFloat(360))
})
}
©IBAction func onPlayAudio(_sender : UIButton){
let title = sender.currentTITLE
let path = Bundle,main.path(forResource: title, ofType: "mp3")
let url = URL(fileURLWithPath: path!)
soundPlayer = try? AVAudioPlayer(contentsOf: url)
soundPlayer.play()
}
©IBAction func onPlayVideo(_sender: UIButton){
if !playFlag{
let path = Bundle.main.path(forResource: "rollinwild", ofType: "mp4")
let url = URL(fileURLWithPath: path!)
let player = AVPlayer(url: url)
player.play()
platerViewController.plater = player
let buttonposition = sender.frame
let x = buttonposition.origin.x-200
let y = buttonposition.origin.y-120
playerViewController.view.frame = cFRect(x:x, y: y, width: 200, height: 112)
self.addChild(playerViewColler)
self.view.addSubview(platerViewController.view)
playFlag = true
}
else{
platerViewController.view.removeFromSuperview()
playFlag = false
}
}
}
NotifcationCenter.default.addOObsercer(self, selecor: #selector(receivedRotation(notification:)),name: NSNotification.Name.
UIDeviceOrientationDidChange, object : nil)
func receivedRotation(notification : NSNotification){
backgroundView.frame = cGRect(x: 0, y: 0, width: self.view.frame.size.width,height: self.view.frame.size.heght)