Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-30-2009, 07:21 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Leeds, England
Posts: 109
Default Possible releasing problem? Getting errors... Please help.

Hi Guys

I am very new to Objective-C and I am clearly having some issues.

I have managed to get my app doing what I want but it crashes with an error after about 7 or 8 cycles.

My app simply plays one of 5 videos picked at random when you hit a button.

I am not sure if my error is to do with the way I use [moviePlayer release].

The code follows.

I would much appreciate any help.

Thanks in advance.

Quote:
#import <MediaPlayer/MediaPlayer.h>
#import "MainView.h"

@implementation MainView

-(void)playMovie {

int r = arc4random() % 5;

NSBundle *bundle = [NSBundle mainBundle];

NSString *movieName = [NSString stringWithFormat:@"movie%d", r];
NSString *moviePath = [bundle pathForResource:movieName ofType:@"m4v"];

NSURL *movieURL;

if (moviePath)
{
movieURL = [NSURL fileURLWithPath:moviePath];
}

if (movieURL != nil) {
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];

moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
moviePlayer.movieControlMode = MPMovieControlModeHidden;
moviePlayer.backgroundColor = [UIColor blackColor];

[moviePlayer play];
}

}

-(void)moviePlayBackDidFinish: (NSNotification*)notification
{
moviePlayer = [notification object];
[moviePlayer release];
}

- (id)initWithFrameCGRect)frame {
if (self = [super initWithFrame:frame]) {
// Initialization code
}
return self;
}


- (void)drawRectCGRect)rect {
// Drawing code
}

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

@end
BenODwyer is offline   Reply With Quote
Reply

Bookmarks

Tags
memory, memory leak, release

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



» Advertisements
» Online Users: 264
19 members and 245 guests
14DEV, @sandris, ADY, ArtieFufkin10, ckgni, Dani77, HemiMG, IphoneSdk, jakerocheleau, JasonR, jimbo, MACralik, NSeven, prchn4christ, Rudy, silverwiz, spiderguy84
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,767
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:55 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0