Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

MPMoviePlayerController Issue in OS4.0

Jessie ArrJessie Arr Posts: 10Registered Users
edited February 2011 in iPhone SDK Development
Greetings! I've recently agreed to work for a friend to try to get his iPhone app updated to be compatible with iPhone OSv4.0. I'm well-versed in C, C# and Java, so I'm making my way alright through the Objective-C code, but am starting to run out of ideas, so I figured I'd turn to the forums and see if other people were experiencing similar issues.

The app is an audiobook-style app, that showcases the services his business provides. eReader is used for the navigation, and it displays videos whose URL is resolved through a sqlite3 database. The Video Player they use extends the MPMoviePlayerController if I'm reading this correctly:
@class ParagraphView;

@interface MPMoviePlayerController (extended)
- (id)videoViewController;
- (void)setOrientation:(int)orientation animated:(BOOL)yorn;
- (void) pause;
- (void) resume; 			  	
@end

The app worked fine in OS version 3.2, however it won't work on any device running OS version 4.0. Instead of playing the videos correctly, it simply crashes the program. With a little fiddling I was able to get it to play audio form the video, with a black screen, but when I attempt to play a subsequent video, the app still crashes (SIGABRT). At first I thought it was an issue with the sqlite database, but since it is able to retrieve the audio correctly, I'm beginning to think the issue may lie in the MPMoviePlayerController. Are there any known compatibility issues in OS 4.0 that could cause this sort of behavior?

I've tried tracing it to a specific line of code, but using breakpoints only allows me to access the event handlers, which all execute and return correctly. But upon, say, clicking the "Next Video" button, the method executes correctly and returns, but once I continue execution, the program crashes.

Any suggestions? It's quite a lot of code which I'm not familiar with, and any nudges in the right direction would be greatly appreciated.
Post edited by Jessie Arr on

Replies

  • finefinfinefin Posts: 258Registered Users
    edited July 2010
    MPMoviePlayerController is deprecated. If you want to play video in iOS 3.2 or later, use MPMoviePlayerViewController

    I've recently posted a How To on this topic: http://www.iphonedevsdk.com/forum/iphone-sdk-development/47868-how-play-video-ipad-fullscreen-landscape-without-controls.html
    <a href="http://canupa.com/products/parallax" target="_blank">[SIGPIC][/SIGPIC]</a><br />
    I <font color="SeaGreen">help</font> you, you <font color="Orange">buy</font> my app - <font color="SeaGreen">you</font> help me, I buy <font color="Orange">your</f
  • Jessie ArrJessie Arr Posts: 10Registered Users
    edited July 2010
    Oh, wow, excellent. I'll read that guide and start updating my code.

    PS- Any idea whether this new code will be backwards compatible with versions 3.2 and earlier, or would I need to write in an if statement to determine what to do on different OS versions?
  • finefinfinefin Posts: 258Registered Users
    edited July 2010
    MPMoviePlayerViewController works since 3.2
    for earlier iOS's you‘ll need that if statement.
    <a href="http://canupa.com/products/parallax" target="_blank">[SIGPIC][/SIGPIC]</a><br />
    I <font color="SeaGreen">help</font> you, you <font color="Orange">buy</font> my app - <font color="SeaGreen">you</font> help me, I buy <font color="Orange">your</f
  • Jessie ArrJessie Arr Posts: 10Registered Users
    edited July 2010
    Okay, I've been wrestling with this for a while now, and I'm still having issues. I can only get it to play the audio still, despite the fact that I'm pretty sure I'm using MPMoviePlayerViewController correctly. Perhaps someone can spot what I'm doing wrong here:
    - (void)play:(NSString*)videoFile 
    {
        if(ctl2 == nil) 
    	{
    		[Objpara VideoContinueSet:0];
    			
            NSBundle *main = [NSBundle mainBundle];
            NSURL *url = [NSURL fileURLWithPath:[[main resourcePath] stringByAppendingPathComponent:videoFile]];
    		
            ctl2 = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
    		
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:[ctl2 moviePlayer]];
    		//ctl.movieControlMode = MPMovieControlModeHidden;				
    
    		MPMoviePlayerController *player = [ctl2 moviePlayer];
    		player.controlStyle = MPMovieControlStyleFullscreen;
    		
    		//[ctl setOrientation:UIDeviceOrientationLandscapeLeft animated:NO]; removing this caused the video to start playing audio			
    		
            [player play];
        }
    }
    

    The object which contains this method is declared with the following interface:
    @interface VideoController : NSObject
    {
        MPMoviePlayerController *ctl;
    	//Next 2 lines are new.
    	MPMoviePlayerViewController * ctl2;
    	MPMovieControlStyle controlStyle;
    	ParagraphView *Objpara;
    }
    

    Any glaringly obvious things I'm doing wrong here?
  • GreatWizardGreatWizard Posts: 4New Users
    edited July 2010
    Jessie Arr wrote: »
    Okay, I've been wrestling with this for a while now, and I'm still having issues. I can only get it to play the audio still, despite the fact that I'm pretty sure I'm using MPMoviePlayerViewController correctly. Perhaps someone can spot what I'm doing wrong here:
    - (void)play:(NSString*)videoFile 
    {
        if(ctl2 == nil) 
    	{
    		[Objpara VideoContinueSet:0];
    			
            NSBundle *main = [NSBundle mainBundle];
            NSURL *url = [NSURL fileURLWithPath:[[main resourcePath] stringByAppendingPathComponent:videoFile]];
    		
            ctl2 = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
    		
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:[ctl2 moviePlayer]];
    		//ctl.movieControlMode = MPMovieControlModeHidden;				
    
    		MPMoviePlayerController *player = [ctl2 moviePlayer];
    		player.controlStyle = MPMovieControlStyleFullscreen;
    		
    		//[ctl setOrientation:UIDeviceOrientationLandscapeLeft animated:NO]; removing this caused the video to start playing audio			
    		
            [player play];
        }
    }
    

    The object which contains this method is declared with the following interface:
    @interface VideoController : NSObject
    {
        MPMoviePlayerController *ctl;
    	//Next 2 lines are new.
    	MPMoviePlayerViewController * ctl2;
    	MPMovieControlStyle controlStyle;
    	ParagraphView *Objpara;
    }
    

    Any glaringly obvious things I'm doing wrong here?

    You don't seem to display the MPMoviePlayerViewController in the view using the addSubview method for example. You need to set it's frame and add it as a subview as you would with a UILabel. Look at the MPMoviePlayerViewController Example .
    http://developer.apple.com/iphone/library/documentation/mediaplayer/reference/mpmovieplayerviewcontroller_class/reference/reference.html

    As you can see in the link, there is also a function to display the MPMoviePlayerViewController modally
  • Jessie ArrJessie Arr Posts: 10Registered Users
    edited July 2010
    You don't seem to display the MPMoviePlayerViewController in the view using the addSubview method for example. You need to set it's frame and add it as a subview as you would with a UILabel. Look at the MPMoviePlayerViewController Example .
    MPMoviePlayerViewController Class Reference

    As you can see in the link, there is also a function to display the MPMoviePlayerViewController modally

    Ah, I've got it working now. I was calling the addSubview method, but I was doing it on an object that was deallocated before the method where I called the play method was invoked, so when play was called, it still wasn't set up properly. Thanks a ton!
  • CeiJayCeiJay Posts: 21Registered Users
    edited July 2010
    Have a look at Dr Touch... for the exact working solution.
    <a href="http://www.twitter.com/tailendchuck" target="_blank">Follow Me on Twitter</a>
  • CeiJayCeiJay Posts: 21Registered Users
    edited July 2010
    Hello All

    iOS4 - iPhone 4 & 3GS

    I have a Table based application using Custom UITableViewCell's. The custom Cell has a UIButton within it for playing a movie file. At the moment I have Arrays to populate the information within each cell depending on the Indexpath. All information within the Cell is placed within cellForRowAtIndexPath and all actions are within didSelectRowAtIndexPath.

    The UIButton within each cell plays a movie using the standard MoviePlayerViewController like so (other code not shown)
    - (void)loadMoviePlayer
    
    {
    
    // Play movie from the bundle NSString *path = [[NSBundle mainBundle] pathForResource:@"Mov2" ofType:@"mp4" inDirectory:nil];
    
    // Create custom movie player
    moviePlayer = [[[CustomMoviePlayerViewController alloc] initWithPath:path] autorelease];
    
    // Show the movie player as modal [self presentModalViewController:moviePlayer animated:YES];
    
    // Prep and play the movie [moviePlayer readyPlayer];
    }
    

    The UIButton within the CustomCell is linked to the following:
    -(IBAction)playMovie {
    
    [self loadMoviePlayer];
    }
    

    Here is an example of Audio being played within didSelectRowAtIndexPath. A Array controllers the stringWithFormat using the TabelView IndexPath. Each Cell plays a certain file...
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSUInteger row = [indexPath row]; NSString *rowTitle = [filmSound objectAtIndex:row];
    
    NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath], rowTitle]]; NSError *error; AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
    
    if (player != nil) { [self setTheAudio: player]; [player release], player = nil;
    
    [self.theAudio setDelegate:self];
    
    [self.theAudio play]; }
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; }
    

    I need to be able to do the same the the movie file actioned by the UIButton in the CustomCell. The - (void)loadMoviePlayer code will not work as an Indexpath is not defined. Have it in didSelectRowAtIndexPath still will not allow me to get the Array working.

    Options in my brain right now... 1. Change the - (void)loadMoviePlayer to include the indexPath as a ref and change the pathForResource to handle the Array. 2. Change the - (void)loadMoviePlayer to include the indexPath as a ref and use an if / else statement will blocks of the MoviePlayer code to repeat the process using (indexPath.row % 2 == 0)

    Recap... UITableView with CustomCell using Array to populate cell information and didSelectRowAtIndexPath need MoviePlayer which is attached to a UIButton within the CustomCell to be played depending on the IndexPath / Cell.

    Your help would be gratefully appreciated. Any question please feel free to ask. Thank you in advance.
    <a href="http://www.twitter.com/tailendchuck" target="_blank">Follow Me on Twitter</a>
  • CeiJayCeiJay Posts: 21Registered Users
    edited July 2010
    If there is no way around this and the Cells didSelectRowAtIndexPath is the only option what about this. The fact that a Audio and a Video file both need to be played depending on the users requirements, what about any of the following options and the process of avenue to achieve them?

    1: UIAlertView with Options
    2: Double Tap Cell
    3: Two Finger Tap Cell
    4: Swipe Cell

    Thoughts?
    <a href="http://www.twitter.com/tailendchuck" target="_blank">Follow Me on Twitter</a>
  • colinhumbercolinhumber Posts: 17Registered Users
    edited July 2010
    finefin wrote: »
    MPMoviePlayerController is deprecated. If you want to play video in iOS 3.2 or later, use MPMoviePlayerViewController

    I've recently posted a How To on this topic: http://www.iphonedevsdk.com/forum/iphone-sdk-development/47868-how-play-video-ipad-fullscreen-landscape-without-controls.html

    Just a note...MPMoviePlayerController and MPMoviePlayerViewController both work fine in iOS 4. MPMoviePlayerController allows you to display videos embedded in screens. You need to add the view provided by the controller as a subview to your screen to get it to display.

    MPMoviePlayerViewController functions similarly but it provides a simple way to display fullscreen video.

    Check you the Apple docs for each here:
    MPMoviePlayerController Class Reference
    MPMoviePlayerViewController Class Reference
  • finefinfinefin Posts: 258Registered Users
    edited July 2010
    Just a note...MPMoviePlayerController and MPMoviePlayerViewController both work fine in iOS 4. MPMoviePlayerController allows you to display videos embedded in screens. You need to add the view provided by the controller as a subview to your screen to get it to display.

    MPMoviePlayerViewController functions similarly but it provides a simple way to display fullscreen video.

    Check you the Apple docs for each here:
    MPMoviePlayerController Class Reference
    MPMoviePlayerViewController Class Reference

    true. that catched my eye a few days ago. thanks for the clarification.
    the only methods of MPMoviePlayerController that are deprecated are:
    backgroundColor & movieControlMode
    <a href="http://canupa.com/products/parallax" target="_blank">[SIGPIC][/SIGPIC]</a><br />
    I <font color="SeaGreen">help</font> you, you <font color="Orange">buy</font> my app - <font color="SeaGreen">you</font> help me, I buy <font color="Orange">your</f
  • wuf810wuf810 Posts: 1,052Registered Users @ @ @ @
    edited February 2011
    finefin wrote: »
    MPMoviePlayerController is deprecated. If you want to play video in iOS 3.2 or later, use MPMoviePlayerViewController

    I've recently posted a How To on this topic: http://www.iphonedevsdk.com/forum/iphone-sdk-development/47868-how-play-video-ipad-fullscreen-landscape-without-controls.html

    Actually it is NOT deprecated in any way.

    One method is deprecated but the difference between MPMoviePlayerController & MPMoviePlayerViewController is essentially that the latter play movie in fullscreen mode straight away. I prefer to play in view and let the user choose fullscreen mode. Therefore I use MPMoviePlayerController.
Sign In or Register to comment.