Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Help new to programming

Hi, anyone know why i would be getting just audio and no video with this code, I am using MPMoviePlayerController to play a video of type .Mov and cant figure out what i've done wrong. Im new to programming so any help would be much appreciated. Also if anyone knows of any good books to read about Objective C to get me started that would be awesome, any advice is good advice at this stage haha. Here's the code also can you call the MPMovieControlStyleNone just straight out like I have



- (void)loadView {


NSString *moviePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Vid.MOV"];


MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:moviePath]];


MPMovieControlStyleNone;

MPMovieControlModeHidden;


[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];


[moviePlayer play];


}

iPhone 3G, iOS 3.1.2

Posted on Aug 4, 2011 10:17 PM

Reply
3 replies

Aug 18, 2011 12:56 AM in response to sam31192

if you are using iOS 4.1 / after, the MPMoviePlayer has some extra properties... If u are before that iOS version


MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL: [NSURL fileURLWithPath: path]];

theMovie.scalingMode = MPMovieScalingModeAspectFill;

theMovie.movieControlMode = MPMovieControlModeDefault;


// Register for the playback finished notification.


[[NSNotificationCenter defaultCenter] addObserver:self



please check the reference library for the MPMoviePlayer.......May it helpful

Aug 18, 2011 5:48 AM in response to sam31192

Hi sam31192,


Take a viewbased template, and name it as MoviePlayer. and add a New File ie UIViewControllerSubClass and name it as CustomMoviePlayer. place a movie which ever you want in resourse folder. i took the 01_01.m4v video. and proceed. the sample code as follows.



MoviePlayerAppDelegate.h


#import <UIKit/UIKit.h>


@classMoviePlayerViewController;


@interface MoviePlayerAppDelegate : NSObject <UIApplicationDelegate> {

UIWindow *window;

MoviePlayerViewController *viewController;

}


@property (nonatomic, retain) IBOutlet UIWindow *window;

@property (nonatomic, retain) IBOutlet MoviePlayerViewController *viewController;


@end


MoviePlayerAppDelegate.m



#import "MoviePlayerAppDelegate.h"

#import "MoviePlayerViewController.h"


@implementation MoviePlayerAppDelegate


@synthesize window;

@synthesize viewController;



#pragma mark -

#pragma mark Application lifecycle


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

// Override point for customization after application launch.


// Add the view controller's view to the window and display.

[windowaddSubview:viewController.view];

[windowmakeKeyAndVisible];


returnYES;

}



- (void)dealloc {

[viewControllerrelease];

[window release];

[super dealloc];

}


@end


MoviePlayerViewController.h


#import <UIKit/UIKit.h>

#import "CustomMoviePlayer.h"


@interface MoviePlayerViewController : UIViewController {



UIButton *btnObj;


CustomMoviePlayer *moviePlayer;


NSURL *movieURL;


}


@property (nonatomic, retain) IBOutlet UIButton *btnObj;

@property (nonatomic, retain) NSURL *movieURL;



-(IBAction)btnClicked;


@end


MoviePlayerViewController.m


#import "MoviePlayerViewController.h"


@implementation MoviePlayerViewController

@synthesize btnObj;

@synthesize movieURL;



// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.

- (void)viewDidLoad {

[superviewDidLoad];

}


-(IBAction)btnClicked{



NSString *moviePath = [[NSBundlemainBundle] pathForResource:@"01_01"ofType:@"m4v"];


moviePlayer =[[[CustomMoviePlayeralloc] initWithPath:moviePath ]autorelease];

[selfpresentModalViewController:moviePlayeranimated:YES];

[moviePlayerreadyPlayer];


}





- (void)didReceiveMemoryWarning {


// Releases the view if it doesn't have a superview.

[superdidReceiveMemoryWarning];



// 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


CustomMoviePlayer.h


#import <UIKit/UIKit.h>

#import <MediaPlayer/MediaPlayer.h>



@interface CustomMoviePlayer : UIViewController {



MPMoviePlayerController *mp;


NSURL *movieURL;


}


- (id)initWithPath:(NSString *)moviePath;

- (void)readyPlayer;



@end


CustomMoviePlayer.m


#import "CustomMoviePlayer.h"



@implementation CustomMoviePlayer

- (id)initWithPath:(NSString *)moviePath

{



// Initialize and create movie URL


if (self = [superinit])

{


movieURL = [NSURL fileURLWithPath:moviePath];

[movieURLretain];


}



returnself;


}


/*---------------------------------------------------------------------------

* For 3.2 and 4.x devices

* For 3.1.x devices see moviePreloadDidFinish:

*--------------------------------------------------------------------------*/

- (void) moviePlayerLoadStateChanged:(NSNotification*)notification

{


// Unless state is unknown, start playback

if ([mp loadState] != MPMovieLoadStateUnknown)

{


// Remove observer

[[NSNotificationCenter
defaultCenter]

removeObserver:self

name:MPMoviePlayerLoadStateDidChangeNotification

object:nil];



// When tapping movie, status bar will appear, it shows up


// in portrait mode by default. Set orientation to landscape


[[UIApplicationsharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRightanimated:NO];



// Rotate the view for landscape playback

[[selfview] setBounds:CGRectMake(0, 0, 480, 320)];

[[selfview] setCenter:CGPointMake(160, 240)];

[[selfview] setTransform:CGAffineTransformMakeRotation(M_PI / 2)];



// Set frame of movieplayer

[[mpview] setFrame:CGRectMake(0, 0, 480, 320)];



// Add movie player as subview

[[selfview] addSubview:[mpview]];



// Play the movie

[mp play];


}


}


/*---------------------------------------------------------------------------

* For 3.1.x devices

* For 3.2 and 4.x see moviePlayerLoadStateChanged:

*--------------------------------------------------------------------------*/

- (void) moviePreloadDidFinish:(NSNotification*)notification

{



// Remove observer

[[NSNotificationCenter
defaultCenter]

removeObserver:self

name:MPMoviePlayerContentPreloadDidFinishNotification

object:nil];



// Play the movie


[mp play];



}


/*---------------------------------------------------------------------------

*

*--------------------------------------------------------------------------*/

- (void) moviePlayBackDidFinish:(NSNotification*)notification

{

[[UIApplicationsharedApplication] setStatusBarHidden:NO];

[[UIApplicationsharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];



// Remove observer

[[NSNotificationCenter
defaultCenter]

removeObserver:self

name:MPMoviePlayerPlaybackDidFinishNotification

object:nil];

[selfdismissModalViewControllerAnimated:YES];



}


/*---------------------------------------------------------------------------

*

*--------------------------------------------------------------------------*/

- (void) readyPlayer

{


[self.navigationControllersetNavigationBarHidden:YES];



mp = [[MPMoviePlayerControlleralloc] initWithContentURL:movieURL];



if ([mp respondsToSelector:@selector(loadState)])

{




// Set movie player layout

[mp setControlStyle:MPMovieControlStyleFullscreen];



[mp setFullscreen:YES];



// May help to reduce latency

[mp prepareToPlay];



// Register that the load state changed (movie is ready)

[[NSNotificationCenterdefaultCenter] addObserver:self

selector:@selector(moviePlayerLoadStateChanged:)

name:MPMoviePlayerLoadStateDidChangeNotification

object:nil];

}


else

{


// Register to receive a notification when the movie is in memory and ready to play.

[[NSNotificationCenterdefaultCenter] addObserver:self

selector:@selector(moviePreloadDidFinish:)

name:MPMoviePlayerContentPreloadDidFinishNotification

object:nil];


}



// Register to receive a notification when the movie has finished playing.

[[NSNotificationCenterdefaultCenter] addObserver:self

selector:@selector(moviePlayBackDidFinish:)

name:MPMoviePlayerPlaybackDidFinishNotification

object:nil];


}


/*---------------------------------------------------------------------------

*

*--------------------------------------------------------------------------*/

- (void) loadView

{


[selfsetView:[[[UIViewalloc] initWithFrame:[[UIScreenmainScreen] applicationFrame]] autorelease]];

[[selfview] setBackgroundColor:[UIColorblackColor]];


}


/*---------------------------------------------------------------------------

*

*--------------------------------------------------------------------------*/

- (void)dealloc

{

[mprelease];

[movieURLrelease];

[superdealloc];

}


@end

Help new to programming

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.