AVPlayerLayer is not visible is view - iphone

I have AVPlayerLayer in a UIView and this is how i add it to the UIView:
[[self.playerView layer] addSublayer:avPlayerLayer];
Also i have UITabBarController with 5 UIViewController.The AVPlayerLayer is in the 5 tab.
And now in iOS 7 when i go to background mode and return to the app the video is still playing but not show in the UIView.
I tried to check if it's still in the UIView with :
NSArray *arr = [self.playerView layer].sublayers;
I tried to remove and add it again but it still not there :
[avPlayerLayer removeFromSuperlayer];
[[self.playerView layer] addSublayer:avPlayerLayer];
and AVPlayerLayer is still there.
Any idea how i can fix this issue?

set the AVPlayer in the AVPlayerLayer only when it is in a visible view.
You probably have another view controller with a view on top of it.

Related

MPMoviePlayerController video does not fill up the entire view

I am trying to add a MPMoviePlayerController view to my app. I am trying to control the position of it in code, and then place my own buttons underneath it (just a fullscreen and play/pause button).
However, the video does not take up the entire area of the video player. Is this normal? Can I make it so the entire thing is video? (This is what I mean: http://i.imgur.com/GWHlD8V.png)
This is how I am implementing it:
in .h:
#interface ViewController : UIViewController
#property (nonatomic, strong) MPMoviePlayerController *moviePlayerController;
#end
in .m:
NSURL *url = [NSURL URLWithString:#"http://localhost:8013/prog_index.m3u8"];
_moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:url];
_moviePlayerController.controlStyle = MPMovieControlStyleNone;
// This places the player exactly where I want it. When I want it full screen
// I can dynamically update these values?
[_moviePlayerController.view setFrame:CGRectMake(100, 181, 650, 500)];
_moviePlayerController.view.layer.borderColor = [UIColor colorWithRed:0.329 green:0.80 blue:0.227 alpha:1].CGColor;
_moviePlayerController.view.layer.borderWidth = 2.0;
_moviePlayerController.shouldAutoplay = YES;
[self.view addSubview:_moviePlayerController.view];
[_moviePlayerController play];
Everything seems to work fine, except there are those black bars above and below the video. I would like it to be just possible, and replace the bottom one with my custom controls. Any thoughts?
Also, is this the best way to position the player?

How can i add a video as a HUD element in iphone sdk

I want to add a video that shows up when i call it but not a typical (stretch-to-bounds) view
similar to the ProgressHud view that loads in the middle and darkens the background. how can I load a video say from LBYoutubeController or natively?
Thanks!
edit: ideally the video box will take up 60-70 % of the screen but again will be centered and overshadowing the background
You need to use a MPMoviePlayerController. You can set the controlStyle to MPMovieControlStyleEmbedded and this will give you a player with no controls. Set the scalingMode to MPMovieScalingModeFill to make the video conform to the frame you set for it regardless of the video's natural layout. Just add the movie player's view to your view hierarchy and you're good to go.
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] init];
moviePlayer.scalingMode = MPMovieScalingModeFill;
moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
[myView addSubview:moviePlayer.view];
To add a dimming view behind this:
UIView *back = [[UIView alloc]initWithFrame:myView.bounds];
back.backgroundColor = UIColor.blackColor;
back.alpha = 0.7;
[myView insertSubview:back belowSubview:myView];

Disable fullscreen mode in iOS Media Player Controller

I want to restrict the media player from entering into the fullscreen mode. Is it possible to customize the controllers of the iPhone media player controller? Can we disable the fullscreen
button in the media player controller?
Check the fullscreen property and setFullscreen:animated methods as noted in the docs.
Edit:
I believe I misread your question--apologies.
Not the best solution, but you could override setFullscreen: to simply ignore the request:
- (void)setFullscreen:(BOOL)full {
// Ignore request
}
As far as customizing the controls, you have the option of setting the controlStyle, but all of these have a full screen button, save the "MPMovieControlStyleNone", which give you no controls. You could combine the MPMovieControlStyleNone and overlay your own control bar.
I would probably go for the latter myself, as a disabled button I expect to work as a user would probably be frustrating.
Hope that at least partially earns-away that down vote. :-)
Edit: Adding some more info/code
So here's just something simple you could do. I build a toolbar using IB
and a bit of code for placement and some silly color (this one's a little harsh actually):
NSArray *array = [[NSBundle mainBundle] loadNibNamed:#"bar" owner:self options:nil];
UIToolbar *toolbar;
if ( nil != array ) {
toolbar = array[0];
}
CGSize barSize = CGSizeMake(self.window.frame.size.width, 44);
CGSize winSize = self.window.frame.size;
[toolbar setFrame:CGRectMake(0, winSize.height - barSize.height, winSize.width, barSize.height)];
[toolbar setTranslucent:YES];
[toolbar setBackgroundImage:nil forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
[toolbar setTintColor:[UIColor colorWithRed:138/255 green:187/255 blue:255/227 alpha:0.4]];
[self.window addSubview:toolbar];
Just connect up the buttons, maybe do a clear-color overlay to handle the tap-to-bring-up-controls functionality that's already common in the movie players.

Screen rotation from device orientation and a new UIView

What is the safest and most effective way place a new UIView within the bounds of the App's UIWindow on the top of the view stack when a screen rotation from Portrait to Landscape occurs? Also, when returning from Landscape to Portrait, to remove this subview.
Basically the App is created as most are:
-UIWindow:
--UIView
---All subviews (including a tabview controller)
I would like to create:
-UIWindow:
--UIView (new, to be placed on top)
--UIView
---All subviews (and triggered by a view controller in here)
Is this wrong? There is surprisingly little documentation to help do this.
If you create a view controller to hold all of your subviews you can just use the rotation functions that will be called for you:
willRotateToInterfaceOrientation:duration:
and
didRotateFromInterfaceOrientation:
So lets say you use didRotateFromInterfaceOrientation you check
if(UIInterfaceOrientationIsLandscape(orientation))
{
[yourView removeFromSuperView];
}
else
{
[self.view addSubView: yourView];
}
See my answer here: https://stackoverflow.com/a/4960988/202451
It should bring you closer to doing custom things like that
I found the a working solution. Might you offer a better one?
ArtsDayAppDelegate *appDelegate = (ArtsDayAppDelegate*)[[UIApplication sharedApplication] delegate];
UIView *landscapeView;
if (!landscapeView) {
landscapeView = [[UIView alloc] initWithFrame: frame];
}
[landscapeView setBackgroundColor:[UIColor blackColor]];
..add various views..
[appDelegate.window.rootViewController.view addSubview:landscapeView];

Making a programmatic iOS UIView fully accessible

I am programmatically building a UINavigationContoller for iOS and am having problems making it fully accessible. In loadView I create the main UIView and set it as NOT accessible:
- (void)loadView
{
CGRect viewRect = [[UIScreen mainScreen] applicationFrame];
UIView *tmp = [[UIView alloc] initWithFrame:viewRect];
[tmp setIsAccessibilityElement:NO];
I then add additional UIViews that contain just background images and also set those as not accessible. All views and controls are added onto the "tmp" UIView created above. Here is a "background" view example:
UIImage* microphone = [UIImage imageNamed:#"microphone.jpg"];
UIView* microphoneView = [[[UIView alloc] initWithFrame: CGRectMake(0,0,viewRect.size.width, microphone.size.height)] autorelease];
[microphoneView setBackgroundColor:[UIColor colorWithPatternImage:microphone]];
[microphoneView setIsAccessibilityElement:NO];
[tmp addSubview:microphoneView];
Finally I add a UIButton, UILabel and UIButtonBarItem. I add these last so they are on the top of the view hierarchy. I add accessibility labels and traits to them. Here is the UIButton:
self.recordImage = [UIImage imageNamed: #"record_button.png"];
self.stopRecordImage = [UIImage imageNamed: #"stop_button.png"];
self.recordButton.accessibilityTraits |= UIAccessibilityTraitStartsMediaSession;
self.recordButton = [[UIButton alloc ] initWithFrame: CGRectMake((viewRect.size.width - recordImage.size.width)/2 , (microphone.size.height + (grayBkg.size.height - recordImage.size.height)/2), recordImage.size.width, recordImage.size.height)];
[self.recordButton setIsAccessibilityElement:YES];
[self.recordButton setAccessibilityLabel: #"toggle recording start"];
[self.recordButton setImage: recordImage forState:UIControlStateNormal];
[self.recordButton addTarget: self action:#selector(processButton:) forControlEvents:UIControlEventTouchUpInside];
[tmp addSubview:recordButton];
finally
....
[self setView:tmp];
[tmp release];
I did call UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, nil); when I push this view onto the stack.
With voiceover on, when the view is displayed I can swipe and give each of my elements (the UIButtonBarItem, UILabel, and UIButton) focus and I can activate them with double tap. However, VoiceOver speaks no information about the elements. Testing in the simulator with the Accessibility Inspector shows the labels I have set via aControl.accessibilityLabel = #"the label";
This view is used to record audio. If I activate the buttons and record the audio and stop recording, VoiceOver will now speak the labels for the elements when I focus them? Why is VoiceOver not speaking the information when the view first loads? Any clues appreciated!
I am testing on an iPad 2 with iOS 4.3.3.
If you'd like your view to not be accessible, use:
[microphoneView setUserInteractionEnabled:NO];
This view is being used for audio recording. The problem was that I was setting the AVSession Category to AVAudioSessionCategoryRecord in the viewDidLoad method. This was causing VoiceOver not to speak the view information. I modified the code to set the category to AVAudioSessionCategoryRecord only when the record button is pushed. And I set it to AVAudioSessionCategoryPlayAndRecord when recording is finished. Here is the thread that explains it fully: http://lists.apple.com/archives/accessibility-dev/2011/Jul/msg00002.html