Displaying some information in overlay to a movie is an easy task. Synchronizing the overlay with the playback controls of MPMoviePlayerController
is a hard task. MPMoviePlayerController+XCDOverlayView lets you add your own view to a MPMoviePlayerController
and automatically synchronizes it with the playback controls.
- Runs on iOS 7.0 and later
MPMoviePlayerController+XCDOverlayView is available through CocoaPods.
pod "MPMoviePlayerController+XCDOverlayView", "~> 1.0.0"
Alternatively, you can manually use the provided static library. In order to do so you must:
- Create a workspace (File → New → Workspace…)
- Add your project to the workspace
- Add the MPMoviePlayerController+XCDOverlayView project to the workspace
- Drag and drop the
libMPMoviePlayerController+XCDOverlayView.a
file referenced from MPMoviePlayerController+XCDOverlayView → Products → libMPMoviePlayerController+XCDOverlayView.a into the Link Binary With Libraries build phase of your app’s target.
These steps will ensure that #import <MPMoviePlayerController+XCDOverlayView/MPMoviePlayerController+XCDOverlayView.h>
will work properly in your project.
MPMoviePlayerController+XCDOverlayView is a category on MPMoviePlayerController which adds a single property:
@property (nonatomic, strong) UIView *overlayView_xcd;
Here is a basic usage example:
MPMoviePlayerViewController *moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];
UIView *overlayView = [UIView new];
// Add subviews to overlayView
moviePlayerViewController.moviePlayer.overlayView_xcd = overlayView;
The overlayView
will be automatically resized to always fit between the top and bottom playback control views. The easiest way to position your views is to use Auto Layout inside the overlay view. See the demo project for an example of subviews centered and aligned at the top and bottom.
## Limitations
-
MPMoviePlayerController+XCDOverlayView only works with full screen movie player controllers.
-
Although MPMoviePlayerController+XCDOverlayView doesn't user private APIs, it relies on implementation details, see the
PlaybackControlViews
function.
MPMoviePlayerController+XCDOverlayView is available under the MIT license. See the LICENSE file for more information.