gpt4 book ai didi

ios - MPMovieViewController 下一个/上一个按钮事件

转载 作者:行者123 更新时间:2023-11-29 02:08:02 26 4
gpt4 key购买 nike

我是 Swift 新手我正在使用 MPMovieviewcontroller当我单击下一个或上一个按钮时,没有事件发生这是代码

import UIKit
import MediaPlayer
class ViewController: UIViewController {
var i : Int = 0

var movieplayer : MPMoviePlayerController!

var arr = ["Akbar","Serial","ak"]
override func viewDidLoad() {
super.viewDidLoad()

UIApplication.sharedApplication().beginReceivingRemoteControlEvents()
self.becomeFirstResponder()
startplaying()

}

override func canBecomeFirstResponder() -> Bool {
return true
}
override func remoteControlReceivedWithEvent(event: UIEvent) {
if event.subtype == UIEventSubtype.RemoteControlNextTrack
{
i++
startplaying()
println(event.subtype)
}
}
func startplaying()
{
if i <= 2
{
let path = NSBundle.mainBundle().pathForResource(arr[i], ofType: "mov")
let url = NSURL.fileURLWithPath(path!)

movieplayer = MPMoviePlayerController(contentURL: url)
}

movieplayer.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height)
movieplayer.view.sizeToFit()

movieplayer.scalingMode = MPMovieScalingMode.AspectFill
movieplayer.fullscreen = true

movieplayer.controlStyle = MPMovieControlStyle.Fullscreen

movieplayer.movieSourceType = MPMovieSourceType.File
movieplayer.prepareToPlay()

self.view.addSubview(movieplayer.view)
}

当我调试这段代码时,remoteControlReceivedWithEvent 函数没有执行

我从here获得donm帮助

最佳答案

试试这个

func startplaying() {
if i <= 2 {
let path = NSBundle.mainBundle().pathForResource(arr[i], ofType: "mov")
let url = NSURL.fileURLWithPath(path!)
movieplayer.contentURL = NSURL.fileURLWithPath(url)
}

阅读更多:Play MP4 using MPMoviePlayerController() in Swift

关于ios - MPMovieViewController 下一个/上一个按钮事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29578436/

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