07-30-2009, 01:47 PM
#1 (permalink )
Registered Member
Join Date: Jul 2009
Posts: 140
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
07-30-2009, 02:08 PM
#2 (permalink )
Registered Member
Join Date: Jul 2008
Posts: 60
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];
08-04-2009, 08:54 PM
#3 (permalink )
Registered Member
Join Date: Jul 2009
Posts: 140
Playing a Video
Quote:
Originally Posted by
japaternoster
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
08-05-2009, 04:51 AM
#4 (permalink )
Registered Member
Join Date: Jul 2009
Location: Los Angeles
Posts: 352
Well, you are using
[self movieURL];
You need to first set up movieURL somehow before you use it.
09-05-2009, 01:48 PM
#5 (permalink )
iPhone SDK fanatics!
Join Date: Aug 2009
Location: Malaysia
Posts: 370
Quote:
Originally Posted by
japaternoster
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!
10-15-2009, 10:45 AM
#6 (permalink )
Registered Member
Join Date: Oct 2009
Posts: 6
Quote:
Originally Posted by
KennyChong
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?
10-15-2009, 12:39 PM
#7 (permalink )
Registered Member
Join Date: Oct 2009
Posts: 6
Quote:
Originally Posted by
Rudacb
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.
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» 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