MPMoviePlayerController Stops Playing After 5 seconds - Swift
Could your moviePlayer
be going out of scope? Have you tried making it a member variable?
moviePlayer
is a local variable of viewDidLoad
, so once that function finishes, I don't see any reason why your player would not be deallocated.
If you instead make it a variable of the class, its lifetime will be extended to match your class's lifetime.
something like
class ViewController: UIViewController {
var player: MPMoviePlayerController?
override func viewDidLoad() {
// ...
self.player = MPMoviePlayerController(contentURL: url) // won't go out of scope at end of viewDidLoad()
// ...
}
video stop after few seconds while playing video from URL using MPMoviePlayerController with error in the console
There is no error actually media player is downloading your video after completing the download it will show this message
Ending background task assertion (6) for playback stall
and then video will be played automatically
Audio file stops playing after a couple seconds
The first thing I would fix is changing your @ObservedObject wrapper to a @StateObject wrapper. This will prevent deallocation if the view updates at some point in the process of playing the sound. Let me know if that works...
Why is the MPMoviePlayerController not pausing?
What to do to make the video paused as it loads ?
Try: [yourPlayer setShouldAutoplay:NO];
Why does MPMoviePlayerController setCurrentPlaybackTime goes to the wrong time?
You should seek using seekToTime or seekToTimeWithSeconds.
CMTime npt = CMTimeMake(9,1);
[self.player seekToTime:npt];
or
CMTime npt = CMTimeMakeWithSeconds(9.3, 600);
[self.player seekToTime:npt toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero];
Related Topics
Errortype' Is Not Convertible to 'Nserror'
Wkwebview Blank After 'Successful' Https Nsurlrequest
iOS Swift Connect Wifi Programmatically and Distinguish Between Bad Password and No Wifi in Range
Swift Add Line Above to Control
How to Handle Oauth-Style Log Ins with Imessage Apps in iOS 10, Xcode 8
Two Uibezierpaths Intersection as a Uibezierpath
Swift - Parse a String Which Contains a Url
Fill Uiview with Color Based on Percentage
Get All List of Uiviewcontrollers in iOS Swift
Split String into Array of Arrays
Double Tap Necessary to Select Tableview Item with Search Bar
User Notification Request Always Come with Default Action Identifier
How to Unwrap the Elements of an Array in Swift? (Ie. Array<Int> as Array<Int>)
How to Set Uitextview's Height Dynamically in Uitableviewcell Based on String Size
How to Change the Nstimeinterval of an Nstimer After X Seconds