I am trying to follow this tutorial link, but i have issues. Can somebody please have a look and let me know what needs to be changed.
I tried to looking up other examples but none seems to work. Please let me know what needs to be changed.
The following is the error
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_MPMoviePlayerController", referenced from:
objc-class-ref in VideoScreenViewController.o
"_MPMoviePlayerPlaybackDidFinishNotification", referenced from:
-[VideoScreenViewController playVideo:] in VideoScreenViewController.o
-[VideoScreenViewController moviePlayBackDidFinish:] in VideoScreenViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Here is the code
// VideoScreenViewController.h
#import <UIKit/UIKit.h>
#import "MediaPlayer/MediaPlayer.h"
#interface VideoScreenViewController : UIViewController
#property (strong, nonatomic) MPMoviePlayerController *moviePlayer;
- (IBAction)playVideo:(id)sender;
#end
}
#import "VideoScreenViewController.h"
#import "MediaPlayer/MediaPlayer.h"
#interface VideoScreenViewController ()
#end
#implementation VideoScreenViewController
#synthesize moviePlayer;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
self.view.backgroundColor = [UIColor clearColor];
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (IBAction)playVideo:(id)sender {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:#"Movie" ofType:#"MOV"]];
moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
moviePlayer.controlStyle = MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay = YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:#"Movie" ofType:#"MOV"]];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
if ([player
respondsToSelector:#selector(setFullscreen:animated:)])
{
[player.view removeFromSuperview];
}
}
#end
Add MediaPlayer.framework to your project..and then try..
i had the same problem today and i found out that the media player framework has to be added correctly: so at first right click on "frameworks" click on "add files to.."
located the framework within the folder "developers/Platforms....etpp" then click on "create folder references for any added folders" and click "add" finally - thats it. After this the error did not appear anymore.
Related
I m downloading a aac file and playing it in MPMoviePlayerController with following code
movieController = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:self.filePath]];
[self.view addSubview:movieController.view];
CGRect screenBound = [[UIScreen mainScreen] bounds];
CGSize screenSize = screenBound.size;
movieController.view.frame = CGRectMake(0,0,screenSize.width, screenSize.height);
[movieController setFullscreen:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(doneBtnMediaPlayer:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
movieController is (nonatomic,strong) class property
this works fine in all iOSes except iOS 5 (and iOS 5 simulator).
In iOS 5 it shows black screen and file is played in background.
Another thing i have noticed is, when i run application over already existing app then its works fine on iOS5 also. But when i delete app from device and then run it, at that time it just shows black screen.
See if this helps:
this is your header (.h) file
#import
#import
#interface ViewController : UIViewController
#property(nonatomic,retain)MPMoviePlayerViewController *playerController;
#end
and this is your implementation file (.m)
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize playerController;
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"gold etche" ofType:#"mov"]];
playerController = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:playerController];
[self.view insertSubview:playerController.view atIndex:0];
playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
playerController.moviePlayer.controlStyle = MPMovieControlStyleDefault;
playerController.moviePlayer.scalingMode = MPMovieScalingModeNone;
[playerController.moviePlayer play];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#end
I tested this in IOS 5 (5.0 AND 5.1) AND IOS 6 AND EVERYTHING SEEMS TO BE FINE
So I created a program where a sound occurs when the device is shaken. Theres a button, that when tapped stops the sound from being played at any time (This is the "reset" method). There's another button, that when pushed displays another view (This is the "infoView" method). The problem occurs when I go the "infoView" then go back to the first view. The sound still play when the device is shaken but the "reset" button becomes unresponsive. Here's what I have so far, any help would be appreciated.
PS. I'm wondering if it has anything to do with FirstResponders? I'm still trying to wrap my head around FirstResponders.
The .h
#import <UIKit/UIKit.h>
#import "AVfoundation/AVfoundation.h"
#interface OldTvViewController : UIViewController{
AVAudioPlayer *audioPlayer;
}
-(IBAction)reset;
-(IBAction)infoView:(id)sender;
#end
the .m
#import "OldTvViewController.h"
#import "AudioToolBox/AudioToolBox.h"
#import "infoViewController.h"
#implementation OldTvViewController
-(IBAction)infoView:(id)sender{
infoViewController *second = [[infoViewController alloc] initWithNibName:Nil bundle:Nil];
[self presentModalViewController:second animated:YES];
[second release];
}
-(BOOL) canBecomeFirstResponder{
return YES;
}
-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{
if (event.subtype == UIEventSubtypeMotionShake) {
//Play throw sound
if(audioPlayer.playing){
[audioPlayer stop];
} else{
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:#"%#/bomb.mp3",[[NSBundle mainBundle] resourcePath]]];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
audioPlayer.numberOfLoops = 0;
[audioPlayer play];
}
}
}
-(IBAction)reset{
[audioPlayer stop];
}
-(void)viewDidAppear:(BOOL)animated{
[self becomeFirstResponder];
[super viewDidAppear:animated];
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
#end
when You go to info view then where your all button available in that class you try this code.
-(void)viewWillDisapeers
{
[audioPlayer stop];
}
or add in this method
-(IBAction)infoView:(id)sender
{
infoViewController *second = [[infoViewController alloc] initWithNibName:Nil bundle:Nil];
[self presentModalViewController:second animated:YES];
[audioPlayer stop];
[second release];
}
I followed this tutorial, and included a video player in my app.
But the problem is that i want to hide the controls, and be able to dismiss the video on screen touch.
I tried putting a big transparent button in front of the video that triggers the dismiss function, but with no luck. the video will always be over the button and the function will never be called.
Is there another way of doing it?
ty
**Hi I think AVPlayer is become more suitable to you,You can use it as below and then add subview if you want to play and if you want to stop remove it from super view
** #import"AVFoundation/AVFoundation.h"
**For creating Player List:
NSString *path1 = [[NSBundle mainBundle] pathForResource:#"hello" ofType:#"mp4"];
AVPlayerItem *first = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:path1]];
player= [AVPlayer playerWithPlayerItem:first];
[self.playerView setPlayer:player];
[player play];
** You have to make uiview for playerview in it :
(id)initWithFrame:(CGRect)frame {self = [super initWithFrame:frame];
if (self) {
// Initialization code.
}
return self;
}
+ (Class)layerClass {
return [AVPlayerLayer class];
}
-(AVPlayer*)player {
return [(AVPlayerLayer *)[self layer] player];
}
-(void)setPlayer:(AVPlayer *)player {
[(AVPlayerLayer *)[self layer] setPlayer:player];
}
PlayerViewControll .H
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#interface PlayerView : UIView UILabel *pageNumberLabel;
int pageNumber;
}
#property (nonatomic, retain) AVPlayer *player;
- (id)initWithPageNumber:(int)page;
PlayerView .M
#import "PlayerView.h"
#implementation PlayerView
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {}
return self;
}
+ (Class)layerClass {
return [AVPlayerLayer class];
}
- (AVPlayer*)player {
return [(AVPlayerLayer *)[self layer] player];
}
- (void)setPlayer:(AVPlayer *)player {
[(AVPlayerLayer *)[self layer] setPlayer:player];
}
MainViewControll .H
#import <AVFoundation/AVFoundation.h>
#import "PlayerView.h"
#interface MainViewController : UIViewController {
IBOutlet PlayerView *playerView;
NSString *url;
AVPlayer *player;
NSMutableArray *arrIteam;
}
#property(nonatomic,retain) NSMutableArray *arrIteam;
#property (nonatomic, retain) AVPlayer *player;
#property(nonatomic ,retain)IBOutlet PlayerView *playerView;
PlayerView.M
#import "MainViewController.h"
#import <QuartzCore/QuartzCore.h>
#implementation MainViewController
#synthesize player,playerView,arrIteam;
- (void)viewDidLoad {
NSString *path1 = [[NSBundle mainBundle] pathForResource:#"hello" ofType:#"mp4"];
AVPlayerItem *first = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:path1]];
arrIteam = [[NSMutableArray alloc] initWithObjects:first,second, third,fourth,nil];
player=[AVPlayer playerWithPlayerItem:[arrIteam objectAtIndex:i]];
[self.playerView setPlayer:player];
[player play];
[super viewDidLoad];
}
You should use UIGestureRecognizer class. See manual for details. Or read this tutorial.
Use this code.
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(stopPlayer)];
[self.view addGestureRecognizer:gestureRecognizer];
gestureRecognizer.cancelsTouchesInView = NO;
[gestureRecognizer release];
in view didload;
And in
- (void) stopPlayer
stop the player and release this player from view.
Hope it helps you.
i just found the solution to my problem in another question asked here. after some minor modifications, the code worked as expected. thank you all.
I´ve created an new ViewController (only with the .h and .m file) and added that code to play a video. After the video has finished, i get a "Exe_bad_access" error.
Error message when adding "NSZombieEnabled=true" to the excecutable as a argument:
"TestPlayingVideo[654:207]
-[MPMoviePlayerController stop]: message sent to deallocated instance
0x63042d0"
Whats wrong with that? How can i do correct memory management when playing video?
#import "TestPlayingVideoViewController.h"
#import <MediaPlayer/MediaPlayer.h>
#implementation TestPlayingVideoViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor darkGrayColor]];
UIButton* btn = [[UIButton alloc] initWithFrame:CGRectMake(50 , 50, 200, 25)];
[btn setTitle:#"press me" forState:UIControlStateNormal];
[btn addTarget:self action:#selector(action:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
[btn release];
}
- (void)action:(id)sender
{
NSLog(#"UIButton was clicked");
NSString *url = [[NSBundle mainBundle] pathForResource:#"mymovie" ofType:#"m4v"];
MPMoviePlayerViewController* moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:url] ];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackComplete:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController.moviePlayer];
[moviePlayerController.moviePlayer play];
//[self.view addSubview:moviePlayerController.view];
[self presentMoviePlayerViewControllerAnimated:moviePlayerController];
}
- (void) moviePlayBackComplete:(NSNotification*) notification {
MPMoviePlayerController* player = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];
[self dismissMoviePlayerViewControllerAnimated];
[player stop];
//[self.view removeFromSuperView];
[player release];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
#end
There's a lot of confusion here over what you're releasing: for example, here's your main alloc of your movie player:
MPMoviePlayerViewController* moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:url] ];
But what you are releasing isn't this moviePlayerController - you're only releasing the .moviePlayer property of your MPMoviePlayerController. Notice when you create your NSNotification you're passing moviePlayerController.moviePlayer, not simply moviePlayerController.
So you're not releasing your moviePlayerController, you're in fact attempting to release a property of that object. Which you shouldn't do - you should release the object, and let it worry about releasing its properties.
I'm not sure if I wrote this code well (get clicks on touching buttons rapidly):
#import "iEngineRoomAppDelegate.h"
#import "iEngineRoomViewController.h"
#import "SoundEffect.h"
#implementation iEngineRoomAppDelegate
#synthesize window;
#synthesize viewController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after app launch
[window addSubview:viewController.view];
[window makeKeyAndVisible];
[self setupSounds];
}
- (void)setupSounds {
NSBundle *mainBundle = [NSBundle mainBundle];
timbal_big_Sound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:#"timbal_big" ofType:#"caf"]];
timbal_sm_Sound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:#"timbal_sm" ofType:#"caf"]];
}
- (IBAction)timbal_big: (id)sender {
SoundEffect *currentSoundEffect= timbal_big_Sound;
[currentSoundEffect play];
}
- (IBAction)timbal_sm: (id)sender {
SoundEffect *currentSoundEffect= timbal_sm_Sound;
[currentSoundEffect play];
}
- (void)dealloc {
[timbal_big_Sound release];
[timbal_sm_Sound release];
[viewController release];
[window release];
[super dealloc];
}
#end
Memory management of the SoundEffect objects is right, if you meant that.