Always show AVPlayer controls - swift

I have an AVPlayerViewController with a AVPlayer in it, and what I need is that the controls of the player (play, pause, time slider) never hides. Right now after more or less 4 seconds of playing the video the become hidden, and you have to tap the screen to show them again. I haven't been able to find a solution to that.. any ideas? thx!

You can set that by using Key-Value Coding
Swift:
// playerController : AVPlayerViewController
playerController.setValue(false, forKey: "canHidePlaybackControls")

Related

Can applicationWillResignActive be used for pausing the application

In the MainViewController, I have a play/pause button. I was having problem in coding for the pause function because when i was using audio player pause it was pausing only the audio player but in background my application was still executing. I have used NSTimer for displaying various UIViewControllers. While audio player is paused it is still displaying UIViewControllers because of NSTimer.Whereas i wanted complete pause audio player & application execution as well at the same time.
I found this -applicationwillresignactive. Do you think this -applicationwillresignactive can help me when i want complete pause audio player plus application pause.
Please suggest.
applicationWillResignActive and applicationDidEnterBackground are called when home button is pressed.

Issue with MPMoviePlayerController playing an audio after a YouTube Video is opened in a Webview

In one View Controller ViewController1, I have tried to open a You tube video embedded in a UIWebview. It opens in the Movie Player window and then I use the "Done" button to come out of the movie player window. Again in another view controller ViewController2 in the same application, I open a MPMoviePlayerController(MPMoviePlayerController *audioplayer) to play an audio file using streaming. However, it remains in the paused state on opening the player. Even when i call the method [audioplayer play], the application automatically sets back the playback state to paused (i rechecked and it is not done through my code).
But if i reopen the application and in view controller ViewController2 i play the audio alone, then MPMoviePlayerController *audioplayer plays successfully.
Any idea what i might be doing wrong ?
This issue was found to be specific only to ios4.0.
This issue doesnt occur in ios4.1 and above.

UIImagePickerController AVAudioPlayer

When I open a UIImagePickerController, I can display the device's camera input stream.
But when I play an AVAudioPlayer with [player play] then the camera stops working.
How can I deal with that?
you can't because UIIMagePickerController is controlling the audio, you will need to use low level AVFoundation in order to do that.
checkout AVCam sample code how to record a movie and add the view as subview , that way you will stay in control of the audio and will be able to play audio.

Stopping video in viewWillAppear:(bool)animated method

In my viewWillAppear:(bool)animated method I want to stop video playing. How can I do this? I am new I don't know much.
I am playing a video on this screen. I have a tab which shows table view. When I click on the tab the table view is shown but video is playing in background: we can hear the music.
If you are using MPMoviePlayerController, call -pause on that object.

Cocoa-Touch How to: MPMoviePlayerController loop?

I have an app with a splash screen. For the splashscreen I've decided to add a m4v movie. I'm using the MPMoviePlayerController to show the movie. Everything is working as expected except for one thing:
I'm trying to make the MPMoviePlayerController loop by subscribing to it's MPMoviePlayerPlaybackDidFinishNotification notification and issuing a [notification.object play] if the data didn't finish loading.
This works partially, it restarts the movie, but there's the fadeout and re-fadein that make it look bad.
Is there any other way to loop the movie?
Or any way to remove the fades?
Try this single line of code:
myPlayer.repeatMode = MPMovieRepeatModeOne;
:)
By complete coincidence I have just written a blog post on this subject - we ran into this problem while we were writing our latest app :)
Assuming that you don't want to follow my shameless plug, here's how we fixed it :
Make sure that the movie starts
and ends on the same frame.
Make the starting frame the Default.png of the app
On startup add Default.png to the window as a UIImageView
Make the movie have a clear background
Play and loop the movie
When the movie ends, it will fade out before it loops round. As Default.png is exactly the same as the start and end frames, the user will never notice :)
When you want to end the movie just remove the Default.png UIImageView and stop the movie - as the background is clear it will just fade out to whatever ui you have in your window.
Sam
I don't think there is any public option to do this. You could try and inspect Erica Sadun's Class Dumps for a method you can override that would handle the fading. Maybe a videoDidFinish method or something.
Have you tried messing around with the backgroundColor property? Apple's MPMoviePlayerController docs say
"The receiver fades to and from the
background color when transitioning to
and from playback...The default color
for this property is black. You can
change this to other colors (including
clear) to provide a more appropriate
transition from your application’s
content to the movie content."
So, you can probably try setting it to [UIColor clearColor] and seeing if that helps.