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 07-30-2009, 01:47 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 140
Default How to play a video from a button

Hi there,
I was wondering if anyone could help me with playing a small movie from a button. Every tutorial/help about this topic plays a movie from a URL, which I don't want. All I want to do is put the .mov file in my xcode project, press a button, and have it play. Your help is greatly appreciated.

Thanks
ybrikeeg is offline   Reply With Quote
Old 07-30-2009, 02:08 PM   #2 (permalink)
Registered Member
 
Join Date: Jul 2008
Posts: 60
Default

Using the tutorials that you have seen, simply change the code that retrieves the remote video to the following. This will retrieve a local file.

Code:
NSString *rootPath = [[NSBundle mainBundle] resourcePath];
NSString *filePath = [rootPath stringByAppendingPathComponent:@"example.mov"];
NSURL *fileURL = [NSURL fileURLWithPath:filePath isDirectory:NO];
yourMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: fileURL];
japaternoster is offline   Reply With Quote
Old 08-04-2009, 08:54 PM   #3 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 140
Default Playing a Video

Quote:
Originally Posted by japaternoster View Post
Using the tutorials that you have seen, simply change the code that retrieves the remote video to the following. This will retrieve a local file.

Code:
NSString *rootPath = [[NSBundle mainBundle] resourcePath];
NSString *filePath = [rootPath stringByAppendingPathComponent:@"example.mov"];
NSURL *fileURL = [NSURL fileURLWithPath:filePath isDirectory:NO];
yourMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: fileURL];
I don't know where to put it? I tried it and got 6 errors. Here's my code.


Code:
#import "VideoViewController.h"
#import <MediaPlayer/MediaPlayer.h>

@implementation VideoViewController
@synthesize moviePlayer;

-(void)viewDidLoad {
	if(!moviePlayer) {
		//moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[self bundleURL]];
		moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[self movieURL]];		
	}
}

-(IBAction)playVideo {
	[moviePlayer play];
	
	[[NSNotificationCenter defaultCenter] addObserver:self 
											 selector:@selector(moviePlayBackDidFinish:) 
												 name:MPMoviePlayerPlaybackDidFinishNotification 
											   object:nil];

	[[NSNotificationCenter defaultCenter] addObserver:self 
											 selector:@selector(moviePreloadDidFinish:) 
												 name:MPMoviePlayerContentPreloadDidFinishNotification 
											   object:nil];
}

-(void) moviePlayBackDidFinish:(id)sender {
	NSLog(@"playback stop");
	[moviePlayer stop];
}

-(void) moviePreloadDidFinish:(id)sender {
	NSLog(@"preload");
}

- (NSURL *)movieURL {
	return [NSURL URLWithString: @"http://code.agilephil.com/fox.m4v"];
	//return [NSURL URLWithString: @"http://code.agilephil.com/video/iphone.m4v"];
}

- (NSURL *)bundleURL {
	NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"fox" ofType:@"m4v"];
	return [NSURL fileURLWithPath:moviePath];
}
	
- (void)dealloc {
	[moviePlayer release];
    [super dealloc];
}

@end
ybrikeeg is offline   Reply With Quote
Old 08-05-2009, 04:51 AM   #4 (permalink)
Registered Member
 
kelvinkao's Avatar
 
Join Date: Jul 2009
Location: Los Angeles
Posts: 352
Send a message via AIM to kelvinkao
Default

Well, you are using
[self movieURL];

You need to first set up movieURL somehow before you use it.
kelvinkao is offline   Reply With Quote
Old 09-05-2009, 01:48 PM   #5 (permalink)
iPhone SDK fanatics!
 
Join Date: Aug 2009
Location: Malaysia
Posts: 370
Default

Quote:
Originally Posted by japaternoster View Post
Using the tutorials that you have seen, simply change the code that retrieves the remote video to the following. This will retrieve a local file.

Code:
NSString *rootPath = [[NSBundle mainBundle] resourcePath];
NSString *filePath = [rootPath stringByAppendingPathComponent:@"example.mov"];
NSURL *fileURL = [NSURL fileURLWithPath:filePath isDirectory:NO];
yourMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: fileURL];

Need help on this one as well.
Where should the example.mov file be located in the XCODE?
Thanks.
__________________
KennyChong
iPhone SDK Fanatic!
KennyChong is offline   Reply With Quote
Old 10-15-2009, 10:45 AM   #6 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 6
Unhappy

Quote:
Originally Posted by KennyChong View Post
Need help on this one as well.
Where should the example.mov file be located in the XCODE?
Thanks.
The Movie Files need to be located in the resources folder of your project. The same place you drop images and the like.

Now, I have a problem with this. My app works great on the simulator, but no video plays on the device... anyone have any ideas?
Rudacb is offline   Reply With Quote
Old 10-15-2009, 12:39 PM   #7 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 6
Thumbs up

Quote:
Originally Posted by Rudacb View Post
The Movie Files need to be located in the resources folder of your project. The same place you drop images and the like.

Now, I have a problem with this. My app works great on the simulator, but no video plays on the device... anyone have any ideas?
Never mind. Found it...

Before anyone else gets bitten by this, remember, the iPhone file system is case sensitive, the simulator may not be depending on your OSX system settings. The simulator played the videos, the phone did not because I had a capital letter in the fileName var while the real file name was all lowercase. I hate it when problems are this simple.
Rudacb is offline   Reply With Quote
Reply

Bookmarks

Tags
button, help!, movie, play

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: 349
19 members and 330 guests
ADY, Alsahir, Dani77, e2applets, JasonR, keeshux, mer10, Monstertaco, piesia, prchn4christ, Promo Dispenser, Robiwan, sebasx, sly24, Touchmint, twerner, zulfishah
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,759
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris
Powered by vBadvanced CMPS v3.1.0

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