Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-13-2008, 02:15 AM
Administrator
 
Join Date: Jun 2008
Location: Arizona
Posts: 395
Send a message via AIM to mxweas Send a message via Yahoo to mxweas Send a message via Skype™ to mxweas
Default Easily Play Movies using the MediaPlayer Framework

Streaming video using the SDK is incredibly easy thanks to the MPMoviePlayerController class. To start playing a movie just run this code below:
Code:
NSURL *myMovieURL = // NSURL that points to a file locally or on the internet.
MPMoviePlayerController* theMovie = [ [ MPMoviePlayerController alloc ] initWithContentURL: myMovieURL ]; // Initialize a MPMoviePlayerController object with the movie.
theMovie.scalingMode = MPMovieScalingModeAspectFill; // Set the scaling mode to fill the screen with the movie.
[ [ NSNotificationCenter defaultCenter ] addObserver: self selector: @selector(movieFinishedCallback:) name: MPMoviePlayerPlaybackDidFinishNotification object: theMovie ]; // Add an observer so we can be told when the movie has finished playing.
[ theMovie play ];
Now we need to implement the movieFinishedCallback method to release theMovie.

Code:
- (void)movieFinishedCallback:(NSNotification *)notification;
{
    [ [ NSNotificationCenter defaultCenter] removeObserver: self name: MPMoviePlayerPlaybackDidFinishNotification object: [ notification object ] ];    
    [ [ notification object ] release ]; // Release the object that sent the notification which is our theMovie object.
}
Max
Reply With Quote
  #2 (permalink)  
Old 08-14-2008, 02:07 AM
Junior Member
 
Join Date: Jul 2008
Posts: 13
Default

This is almost identical to the code I wrote today for this, thanks for the validation . I should have some example code I can release very soon, to give back.
Reply With Quote
  #3 (permalink)  
Old 08-18-2008, 05:44 PM
Member
 
Join Date: Jul 2008
Location: Lahore, Pakistan
Posts: 34
Default

ok, i have one question. Can i loop any video..... ?

i just need to know -- can a 20 second video be looped without any break
i think, you have to call the media player framework?
Reply With Quote
  #4 (permalink)  
Old 08-18-2008, 06:27 PM
Junior Member
 
Join Date: Jul 2008
Posts: 13
Default

I'm not sure if this would work, but one thing you can try on the moviePlayer callback isPlaybackFinished, (or whatever the delegate method's name is) Get the notification object and send the message start back to the movie.

I'll try it later and see if it works.
Reply With Quote
  #5 (permalink)  
Old 08-18-2008, 11:44 PM
Administrator
 
Join Date: Jun 2008
Location: Arizona
Posts: 395
Send a message via AIM to mxweas Send a message via Yahoo to mxweas Send a message via Skype™ to mxweas
Default

I've tried it and the moviePlayer fades out, then fades back in. If you're looking for a loop like in the iPod app, this is not it.

Max
Reply With Quote
  #6 (permalink)  
Old 08-18-2008, 11:51 PM
Junior Member
 
Join Date: Jul 2008
Posts: 13
Default

If the fading is the problem, then maybe paste a UIView overlay with a background color to match your MPMoviePlayerController when beginning the movie.

However after thinking about it the bigger problem would be, that the moviePlayBackDidFinishNSNotification*)notificati on delegate call happens anytime the movie stops.

Even if you click done halfway through.
Reply With Quote
  #7 (permalink)  
Old 08-19-2008, 10:15 AM
Member
 
Join Date: Jul 2008
Location: Lahore, Pakistan
Posts: 34
Default

Thanks Max and Bainfu for your quick replies.
Reply With Quote
  #8 (permalink)  
Old 08-23-2008, 01:35 PM
Moderator
 
Join Date: Aug 2008
Posts: 30
Default

Is there a way to make the movie player follow HTTP 302 Founds? I am trying to use a URL to play that redirects a few times before getting to the actual file. When using the final URL it works fine, but the original won't.
Reply With Quote
  #9 (permalink)  
Old 08-23-2008, 05:44 PM
Administrator
 
Join Date: Jun 2008
Location: Arizona
Posts: 395
Send a message via AIM to mxweas Send a message via Yahoo to mxweas Send a message via Skype™ to mxweas
Default

I use redirects with my videos and they work fine. You could check NSURL or whatever you are passing to it to see if you can tell it to follow redirects.

Max
Reply With Quote
  #10 (permalink)  
Old 09-23-2008, 10:13 PM
Junior Member
 
Join Date: Sep 2008
Posts: 1
Default question concerning playback

I was wondering if there was a possibility of having a movie be played in the middle of a UIView and have a button affect the movie, have it replay the movie or a different one altogether.

Basically im looking to have an animated character on a UIView and I was hoping to use videos that i have of the character to have him demonstrate different functions. Would this be possible ?
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 01:03 AM.