How to play audio/video within user specified time frame in MPMovieplayer

269 views Asked by At

I want to play a video within a user specified time interval. I am using MPMoviePlayerand my video is playing. Now I want to set the time frame that video should play. Let's say my video duration 5mins. when click on the video user can specify the time that how long he want to watch or listen. If he give 10minuts, my 5 mins video should play 10mins if he specify 2 mins, my 5 mins video should play only 2 mins.

How can I do this using MPMovieplayer Please help me, thanks

1

There are 1 answers

0
Wei Wen Hsiao On

How about using a timer to set the time that video should play. The code in swift version:

let timer = NSTimer(timeInterval: 'your_Time_Interval', target: self, selector: "stopVideo", userInfo: nil, repeats: false)

func stopVideo()
{
    MPMovieplayer.stop()
}

If the time bigger than the time of the video, you could just use the same timer concept to play the video again. But remember to stop it when time up.

Hope this solution could help you!