I have MPMoviePlayerController and it start with url but it doesn't resume after pausing, I don't know how to resume after successful buffer of video.
Please help me.
Thanks in advance.
I tried with this
self.moviePlayer = MPMoviePlayerViewController(contentURL: url)
self.moviePlayer?.moviePlayer.prepareToPlay()
self.moviePlayer?.moviePlayer?.movieSourceType = MPMovieSourceType.Unknown
self.moviePlayer?.moviePlayer.play()
self.presentMoviePlayerViewControllerAnimated(self.moviePlayer)
You can use MPMoviePlayerPlaybackStateDidChangeNotification to get notified for state change. Then check MPMoviePlaybackState for desired state and resume your video. For more reference you can refer to apple document for MPMoviePlayerController. Also set its shouldAutoplay property to YES.
Also checkout this answer in case your self.moviePlayer is not working properly because it is getting out of scope. Try using it as a member variable.
Related
I'm streaming audio in my iOS swift app.
The main issue is that avplayer has to load all the file to start the playback.
Using playImmediatelyAtRate doesn't work because playbackBufferEmpty is always true until the file is completely downloaded which can be an issue on long audio files.
Any ideas?
Not really AVPlayer related answer but you could use VLCKit to handle the stream.
Here is a basic sample in Swift:
let mediaPlayer = VLCMediaPlayer()
// replace streamURL by the url of the stream
mediaPlayer.media = VLCMedia(url: streamURL)
// outputView is the view where you want to display the stream
mediaPlayer.drawable = outputView
mediaPlayer.play()
If you have any issue with VLCKit, feel free to ping me!
For iOS >10 I set:
avplayer.automaticallyWaitsToMinimizeStalling = false;
and that seemed to fix it for me. This could have other consequences, but I haven't hit those yet.
I got the idea for it from:
AVPlayer stops playing video after buffering
I have integrated amazon polly to one of my project in swift and asking it to TTS multiple set of text strings. Certainly I am using there below set of instructions to play sound:
builder.continueOnSuccessWith { (awsTask: AWSTask<NSURL>) ->
Any? in
// The result of getPresignedURL task is NSURL.
// Again, we ignore the errors in the example.
let url = awsTask.result!
// Try playing the data using the system AVAudioPlayer
self.audioPlayer.replaceCurrentItem(with: AVPlayerItem(url: url as URL))
self.audioPlayer.play()
return nil
}
While debug I found that replaceCurrentItem is adding a new item to play and ignoring the previous. I would like to have some suggestions as how the polly handle such multiple calls within its framework.
Any help appreciated! Thanks
I could able to make this work by inserting each operation to AVQueuePlayer and playing at last, but I am keen to know how amazon handle's multiple file play in polly
Im new to swift but i like it more than obj-c as it looks a bit like java does to me from syntax wise compared to obj-c.
My problem is now that most of the source code samples are for obj-c so theyre unreadable for me =)
Anyway i managed to run a few code snippets like this(im not at my mac but they were similar):
let steamingURL:NSURL = NSURL(string: "http://....")!
let player = AVPlayer(URL: steamingURL)
player.allowsExternalPlayback = false
PlayWorkoutViewController.playerController = AVPlayerViewController()
PlayWorkoutViewController.playerController.player = player
self.addChildViewController(PlayWorkoutViewController.playerController)
self.view.addSubview(PlayWorkoutViewController.playerController.view)
PlayWorkoutViewController.playerController.view.frame = videoContainerView.frame
PlayWorkoutViewController.playerController.showsPlaybackControls = false
player.play()
resulting in a Play Button with a line trough it, it doesnt play the Stream.
The stream source is a mpg1/2 stream according to VLCPlayer and its coming from a Linux based satellite receiver.
Another thing i tried was to change that "string:" part to "fileURLWithPath:" at the NSURL variable but that didnt work either.
Is there a way to Buffer the stream or is this just a codec issue, what workaround options do i have?
Im hesitating since three days, i hope its not a duplicate question, thanks.
EDIT: content of the stream.m3u file:
EXTM3U
EXTVLCOPT--http-reconnect=true 192.168.178.20:8001/1:0:1:445D:453:1:C00000:0:0:0:
Security setting might be the problem. Go to info.plist and Add "App Transport Security Settings". Under that add "Allow Arbitrary Loads" and set it to YES. I hope this fixes the problem.
I am using the new Apple Music API with MPMusicPlayerController but play method doesn't work in the first time called, but after the second or third time.
My code is the following:
MPMusicPlayerController *appleMusicPlayer = /*access instantiated player*/;
[appleMusicPlayer setQueueWithStoreIDs:#[url]];
[appleMusicPlayer play];
The player is instantiated as follows:
_appleMusicPlayer = [MPMusicPlayerController applicationMusicPlayer];
_appleMusicPlayer.repeatMode = MPMusicRepeatModeNone;
_appleMusicPlayer.shuffleMode = MPMusicShuffleModeOff;
[_appleMusicPlayer beginGeneratingPlaybackNotifications];
The url passed in setQueueWithStoreIDs method is a NSString with a country-specific valid iTunesID. I provide you with a screenshot of NSLog output of url after above play method is called.
Any help would be much appreciated.
Make sure url is a string of the store ID!
You can get that here: https://affiliate.itunes.apple.com/resources/documentation/itunes-store-web-service-search-api/
I have this stream url with mp3 type: http://www.slobodnyvysielac.sk/redata/other/play.php?file=informacna%20vojna%20-%202015-02-17%20financne%20skupiny.mp3
when I open this url with Safari or Chrome, it can play, but I can't play it with objectives C code (iOS).
Please tell me the solution!
Thanks all!
player = [[AVPlayer alloc] initWithURL:[NSURL URLWithString:#"http://archive.slobodnyvysielac.sk/informacna%20vojna%20-%202015-02-10%20hudo.mp3"]];
[player play];
Inside your view controller or whatever class you have define this, don't define it inside the event where you stream.
AVPlayer *player
EDIT:
There was a problem with your URL, if you open it in the browser, it opens a flash player so I inspected the flash object and got the original MP3 url which will stream, and you can compare how Google Chrome e.g. reacts to both URLs to notice the difference, now the url in my above code is the correct one