MPMoviePlayerController release problem - iphone

here is code
- (void)applicationDidFinishLaunching:(UIApplication *)application {
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"sample_mpeg4" ofType:#"mp4"];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
moviePlayer.movieControlMode = MPMovieControlModeHidden;
[moviePlayer play];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlaybackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
}
- (void) moviePlaybackDidFinish:(NSNotification*)notification
{
MPMoviePlayerController *theMovie = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification
object:theMovie];
[theMovie stop];
[theMovie release];
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
}
so my problem is my apps memory usage goes additional 3MB , it stays there even after release,does that mean memory does not get released?

Look at your code in
- (void) moviePlaybackDidFinish:(NSNotification*)notification
MPMoviePlayerController *theMovie = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie];
Are you sure "theMovie" is your created "moviePlayer"? I believe they are different memory address because you didn't assign a object when you register the notification. Make sure
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlaybackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
Then try it again.

Related

Video from web cam is not streaming in iPhone/Objective c

I am trying this code but it shows a still image, and not proper video streaming. However it shows the video, but only for some time.
[reykjavikurtjorn loadRequest:[NSMutableURLRequest requestWithURL:[NSURL URLWithString:#"http://213.167.154.114/mila/_definst_/tjornin.stream/playlist.m3u8"]]];
[super viewDidLoad];
NSURL *url = [NSURL fileURLWithPath:#"http://www.domain.com/myVideo.mp4"];
MPMoviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlaybackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
mpvc.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[self presentMoviePlayerViewControllerAnimated:mpvc];
and the delegate
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
if ([player respondsToSelector:#selector(setFullscreen:animated:)]) {
[player.view removeFromSuperview];
}

MPMoviePlayerController not working, no Notifications either

Can someone please point out why this would NOT work?
NSURL *url = [NSURL fileURLWithPath:ImageName];
MPMoviePlayerController *video = [[MPMoviePlayerController alloc] initWithContentURL:url];
NSLog(#"%#", ImageName);
NSLog(#" %#", url);
[canvas addSubview:video.view];
video.view.frame = canvas.bounds;
// [video setControlStyle:MPMovieControlStyleEmbedded];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(myMovieCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:video];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(myMovieCallback:) name:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey object:video];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(myMovieCallback:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:video];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(myMovieCallback:) name:MPMoviePlayerLoadStateDidChangeNotification object:video];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(myMovieCallback:) name:MPMoviePlayerNowPlayingMovieDidChangeNotification object:video];
[video prepareToPlay];
None of the callbacks trigger. Just have a blank space where canvas is.
Keeping the MPMoviePlayerController reference in an instance variable or property worked for me.

Play 2 videos from url one after another

In my application i want to play 2 url videos one after another.
This is my code:
`- (void)viewDidLoad {
NSLog(#"viewDidLoad");
player = [[MPMoviePlayerController alloc] initWithContentURL:[self movieURL]];
[NSNotificationCenter defaultCenter]addObserver:self
selector:#selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player play];
[super vieDidLoad];
}
- (NSURL *)movieURL {
return [NSURL URLWithString: #"https://s3.amazonaws.com/adplayer/colgate.mp4"];//First video url after this video complete.I want to play the next url video.
}
- (void) movieFinishedCallback:(NSNotification*) aNotification {
NSLog(#"movieFinishedCallback");
player = [aNotification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player autorelease];
}
`
After one url video completed i want to play the next url video.
please anyone help me.
I have store the url's in array like this,
array=[[NSArray alloc] initWithObjects:#"https://s3.amazonaws.com/adplayer/colgate.mp4",#"https://s3.amazonaws.com/ventuno-platform-flv-sep2010/happy_family.mp4",nil];
Then how can i retrive the url in - (void) movieFinishedCallback:(NSNotification*) aNotification {
}method.please give me guidance in this.
I a have not tested it, but is should work, You might need it modify it little bit. At least, you now have an idea, how this can be done
-(void)viewDidLoad
{
[self initializPlayer];
}
static int i;
-(void)initializPlayer
{
if(i<=[arrMovieURL count])
i +=1;
else {
i = 0;
}
if(player)
{
[player release];
player = nil;
}
player = [[MPMoviePlayerController alloc] initWithContentURL:[arrMovieURL objectAtIndex:i]];
[NSNotificationCenter defaultCenter]addObserver:self
selector:#selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player play];
}
- (void) movieFinishedCallback:(NSNotification*) aNotification {
NSLog(#"movieFinishedCallback");
player = [aNotification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
//calling again to play the next video
[self initializPlayer];
}

MPMoviePlayer-Notification doesn´t get called

HI,
i want to play a movie using MPMoviePlayerViewController and listen to a MPMoviePlayerPlaybackDidFinishNotification, but it doesn´t get called. Any ideas on that?
Would be helpful to get any hints on that.. Thanks you
Here´s my code:
NSString *url = [[NSBundle mainBundle] pathForResource:[sender contentName] ofType:#"m4v"];
MPMoviePlayerViewController* moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:url] ];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackComplete:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController];
moviePlayerController.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
[self presentMoviePlayerViewControllerAnimated:moviePlayerController];
[moviePlayerController.moviePlayer play];
}
- (void) moviePlayBackComplete:(NSNotification*) notification {
NSLog(#"moviePlayBackComplete complete");
MPMoviePlayerController* moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController];
[self dismissMoviePlayerViewControllerAnimated];
[moviePlayerController release];
}
You're trying to get notifications from a MPMovePlayerViewController but I'm pretty sure only MPMoviePlayerController provides them. Try and change your notification setup
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackComplete:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController.moviePlayer];

How to change view after video played?

I would like to make an application in which, when I press a button, one video starts playing, and when it finishes or when I press "done" button it should take me to a view different from the first one where I launched the video.
Update:
This is the code I'm using but it doesn't work. I need to use MPMoviePlayerViewController instead of MPMoviePlayerController. Any idea?
NSBundle *Bundle = [NSBundle mainBundle];
NSString *moviePath = [Bundle pathForResource:#"video1" ofType:#"m4v"];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
- (void) movieFinishedCallback:(NSNotification*) notification {
MPMoviePlayerViewController *moviePlayer = [notification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[moviePlayer release];
// dismiss your view or present a new view here.
View1 *View1b = [[View1 alloc] initWithNibName:nil bundle:nil];
View1b.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController: View1b animated:YES];
}
Unless you need something very custom, MPMoviePlayerController will probably suit your needs. You can add it to your view or a smaller subview, and you can disable the controls for fullscreen, etc. The url can be to a local file or remove resource.
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: url];
[player view].frame = [myView bounds];
[myView addSubview: [player view]];
[player play];
Observe the MPMoviePlayerPlaybackDidFinishNotification to figure out when it is done, and from that observer's block or selected method you can dismiss your view or present a new view.
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
Then
- (void) movieFinishedCallback:(NSNotification*) notification {
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player release];
// dismiss your view or present a new view here.
}