开发者

How do you hide MPMoviePlayer video controls?

I have managed to make my app play a video, but I am a beginner and I don't know how to code that well, I can't figure out how to hide the video controls. I couldn't find out how to from the Internet, since my code is different from others and I don't know where to put single pieces of code in my code. This is my code:

//
//  PlayVideoViewController.m
//  PlayVideo
//
//  Created by Barry on 5/18/11.
//  Copyright __MyCompanyName__ 2011. All rights reserved.
//

#import "PlayVideoViewController.h"
#import <MediaPlayer/MediaPlayer.h>

@implementation PlayVideoViewController

- (void)viewDidLoad {
    
    NSString *url = [[NSBundle mainBundle] 
                                         pathForResource:@"Charlie" 
                                         ofType:@"mp4"];
        
    MPMoviePlayerController *player = 
        [[MPMoviePlayerController alloc] 
         initWithContentURL:[NSURL fileURLWithPath:url]];

    [[NSNotificationCenter defaultCenter] 
         addObserver:self
         selector:@selector(movieFinishedCallback:)                                              
         name:MPMoviePlayerPlaybackDidFinishNotification
         object:player];
    
    //---play movie---
    [player play];    
    [super viewDidLoad];    
}

- (void) movieFinishedCallback:开发者_运维技巧(NSNotification*) aNotification {
    MPMoviePlayerController *player = [aNotification object];
    [[NSNotificationCenter defaultCenter] 
         removeObserver:self
         name:MPMoviePlayerPlaybackDidFinishNotification
         object:player];    
    [player autorelease];    
}



/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
        // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
        
        // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
        // Release any retained subviews of the main view.
        // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

@end

How can I change this to disable the video controls?


Define the controlStyle property on the MPMoviePlayerController object.

Constants describing the style of the playback controls.

enum {
   MPMovieControlStyleNone,
   MPMovieControlStyleEmbedded,
   MPMovieControlStyleFullscreen,
   MPMovieControlStyleDefault = MPMovieControlStyleFullscreen
};
typedef NSInteger MPMovieControlStyle;

In your case you would write player.controlStyle = MPMovieControlStyleNone

Read more from here


NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                     pathForResource:@"YOUR-RESOURCE-HERE" ofType:@"m4v"]];
MPMoviePlayerViewController *playercontroller = [[MPMoviePlayerViewController alloc]
                                                 initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:playercontroller];
//[self.view addSubview: playercontroller.view];
[introMovie addSubview:playercontroller.view];
playercontroller.moviePlayer.view.frame = CGRectMake(0.0, 0.0, 320.0, 480.0);
playercontroller.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
playercontroller.moviePlayer.controlStyle = MPMovieControlStyleNone;
[playercontroller.moviePlayer prepareToPlay];
[playercontroller.moviePlayer play];
playercontroller = nil;
NSLog(@"Video is Playing");


Just for reference to other people, in iOS 6 the code is

player.moviePlayer.controlStyle=MPMovieControlStyleNone;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜