gpt4 book ai didi

swift - 来自 MPMoviePlayerController 的音频在转至下一个 View Controller 后继续播放

转载 作者:搜寻专家 更新时间:2023-11-01 05:40:54 25 4
gpt4 key购买 nike

添加视频文件后,即使按下一个转至下一个 VC,视频预览中的音频也会继续播放。

有什么方法可以在按下 segue 后停止播放音频?

var objMoviePlayerController: MPMoviePlayerController = MPMoviePlayerController()
var urlVideo: NSURL = NSURL()

@IBOutlet weak var videoprofileView: UIImageView!
@IBOutlet weak var addvideoBtn: UIButton!

override func viewDidLoad() {
super.viewDidLoad()

var theWidth = view.frame.size.width
var theHeight = view.frame.size.height

videoprofileView.frame = CGRectMake(0, 50, theWidth, theWidth)
addvideoBtn.center = CGPointMake(theWidth/2, self.videoprofileView.frame.maxY+50)
}

@IBAction func addvideoBtn_click(sender: AnyObject) {
var ipcVideo = UIImagePickerController()
ipcVideo.delegate = self
ipcVideo.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
ipcVideo.allowsEditing = true
ipcVideo.videoMaximumDuration = 15

var kUTTypeMovieAnyObject : AnyObject = kUTTypeMovie as AnyObject
ipcVideo.mediaTypes = [kUTTypeMovieAnyObject]
self.presentViewController(ipcVideo, animated: true, completion: nil)
}

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
urlVideo = (info as NSDictionary).objectForKey(UIImagePickerControllerMediaURL) as! NSURL
self.dismissViewControllerAnimated(true, completion: nil)

objMoviePlayerController = MPMoviePlayerController(contentURL: urlVideo)
objMoviePlayerController.movieSourceType = MPMovieSourceType.Unknown
objMoviePlayerController.view.frame = self.videoprofileView.bounds
objMoviePlayerController.scalingMode = MPMovieScalingMode.AspectFill
objMoviePlayerController.controlStyle = MPMovieControlStyle.None
objMoviePlayerController.shouldAutoplay = true

videoprofileView.addSubview(objMoviePlayerController.view)

objMoviePlayerController.prepareToPlay()
objMoviePlayerController.play()
}

@IBAction func next_click(sender: AnyObject) {
let data:NSData = NSData(contentsOfURL: urlVideo)!
let file = PFFile(name:"video.mp4", data:data)
var currentUser = PFUser.currentUser()!
currentUser["video"] = file

currentUser.saveInBackgroundWithBlock( {
(succeeded: Bool, error: NSError?) -> Void in
if error == nil {
println("video saved")
} else {
println("couldn't save video")
}
})
}

最佳答案

在转到下一个 View Controller 之前告诉您的视频停止

override func prepareForSegue(segue: UIStoryboardSegue?, sender: AnyObject?) {
objMoviePlayerController.stop()
}

MPMediaPlayback Protocol Reference

关于swift - 来自 MPMoviePlayerController 的音频在转至下一个 View Controller 后继续播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30608190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com