MPMoviePlayerController not playing local video - ios

My video did not start to play in simple project
So I tried some examples to incorporate in the project.
First of all I added two frameworks MediaPlayer and MobileCoreService and imported .h file
#import <MediaPlayer/MediaPlayer.h>
#import <MobileCoreServices/MobileCoreServices.h>
Then added properties
#property (copy, nonatomic) NSURL *movieURL;
#property (strong, nonatomic) MPMoviePlayerController *player;
And last step was adding to viewDidLoad next code
_movieURL = [NSURL URLWithString:#"Movie.m4v"];
_player = [[MPMoviePlayerController alloc] initWithContentURL:_movieURL];
_player.view.frame = CGRectMake(0 , 0, 400, 300);
_player.controlStyle=MPMovieControlStyleNone;
_player.scalingMode = MPMovieScalingModeAspectFill;
[self.view addSubview:_player.view];
[_player play];
Movie.m4v file in my root folder of application.
Also I'm trying to start it with help of action button, but code is working with
[_player play];
but I get a black rectangle, and if I understand right my addSubview part is working
Searching another examples but almost find same realisation.
http://photokarma.bl.ee/ios/VideoTest.zip archive with src code and file

Try This code..
NSString *path = [[NSBundle mainBundle] pathForResource:#"Movie" ofType:#"m4v" inDirectory:nil];
NSURL *movieURL = [NSURL fileURLWithPath:path];
player= [[ MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
player.view.frame = CGRectMake(184, 200, 400, 300);
[self.view addSubview:player.view];
[player play];
Source Code:http://ishare-edu.blogspot.in/2012/10/how-to-play-audio-and-video-in-iphone.html
Hope it works...

Please resolve this line in Your code.
_movieURL = [NSURL URLWithString:#"Movie.m4v"];
if this is an http url then write complete like http://www.yourserver.com/../../Movie.m4v
or you accessing this video from locally within your iOS App then provide the full path like
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"Movie" ofType:#"m4v"];
NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
then after finding the movie url you can init your player like
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
player.view.frame = CGRectMake(184, 200, 400, 300);
[self.view addSubview:player.view];
[player play];
As per your Comment do you have any idea why i get urlpath nil?
Check that:
The Movie file exists in your copy of the source code.Also review that Xcode project has a reference to that file (if it's red, it means the file isn't actually present)
In your target in Xcode, look at "Build Phases" and reveal the "Copy Bundle Resources" build phase. That file should be present. If it isn't, press the + button and select it.
As per your given code i resolved and found this bug as i also discussed.
Tick both
Add To Targets Your Project Name
Copy item into your destination group
So you need to remove the video file and add it again with these both tick.

Try in Simple steps:
Step 1: Import MediaPlayer framework #import <MediaPlayer/MediaPlayer.h>
Step 2: Set delegate in .h file UIViewController<MPMediaPlayback>
Step 3:
- (void)viewDidLoad
{
[super viewDidLoad];
NSBundle *bundle = [NSBundle mainBundle];
NSString *fileLocation= [bundle pathForResource:#"file_video" ofType:#"m4v"];
NSURL *vedioURL =[NSURL fileURLWithPath:fileLocation];
MPMoviePlayerViewController *videoPlayerView = [[MPMoviePlayerViewController alloc] initWithContentURL:vedioURL];
[self presentMoviePlayerViewControllerAnimated:videoPlayerView];
[videoPlayerView.moviePlayer play];
}
-(void)endSeeking
{
[self.navigationController popViewControllerAnimated:NO];
}
-(void)stop
{
[self.navigationController popViewControllerAnimated:NO];
}

Related

MPMoviePlayerController set unknown text

I use the MPMoviePlayerController for playing video. It works, but it displays unknown strings which I think it is related to its localization files:
The code for playing video is here:
NSString *videoPath = [[NSBundle mainBundle] pathForResource:#"test" ofType:#"m4v"];
NSURL *streamURL = [NSURL fileURLWithPath:videoPath];
MPMoviePlayerController *moviplayer =[[MPMoviePlayerController alloc] initWithContentURL: streamURL];
[moviplayer prepareToPlay];
[moviplayer.view setFrame: self.view.bounds];
[self.view addSubview: moviplayer.view];
moviplayer.fullscreen = YES;
moviplayer.shouldAutoplay = YES;
moviplayer.repeatMode = MPMovieRepeatModeNone;
moviplayer.movieSourceType = MPMovieSourceTypeFile;
[moviplayer play];
How to solve this problem?
After looking to all part of my project, I find that the below class (category) which is used to set the default language for the application, yields to this bug:
https://github.com/cmaftuleac/BundleLocalization
Use this forked class solved my problem by not use swizzling method for UIKit bundle:
https://github.com/jbolter/BundleLocalization
https://github.com/jbolter/BundleLocalization/commit/4eedcf45a315a4a5f3ddaf9521f3cadec6632bcc

Cannot play audio in Xcode project

This code works in a test app, but not in the app in which I want the audio to play.
-(void) playTutorialAudio
{
_theAudioFile = [[NSBundle mainBundle] pathForResource:#"Welcome" ofType:#"mp3"];
NSLog(#"playTutorialAudio _theAudioFile %#",_theAudioFile);
NSURL *playTutorialURL = [NSURL fileURLWithPath:_theAudioFile ];
_audioPlayAlert = [[AVAudioPlayer alloc] initWithContentsOfURL:playTutorialURL error:NULL];
[_audioPlayAlert setDelegate:self];
[_audioPlayAlert prepareToPlay];
_audioPlayAlert.volume = 1.0;
[_audioPlayAlert play];
}
The code works with other audio files.
It will work, You need to change your implementation like this. Please notice your init method.
#property (nonatomic, retain) AVAudioPlayer *cellTapSound;
may be in viewDidLoad
cellTapSound = [[AVAudioPlayer alloc] initWithContentsOfURL:[[NSBundle mainBundle] URLForResource:#"ting" withExtension:#"wav"] error:nil];
[cellTapSound prepareToPlay];
Now may be on click of some button, you can give a shot like this :
if (cellTapSound.isPlaying) [cellTapSound setCurrentTime:0.0];
[cellTapSound play];
hope that helps.

No Visible interface for 'AVAudioPlayer declares the selector initWithUrl:'

I am trying to play a button click sound,also that i should be able to manage click sound along with volume button.
What i have done is
Added AVFoundationFramework to project,
in .h file
#import <AVFoundation/AVAudioPlayer.h>
#import <AVFoundation/AVFoundation.h>
in .m file under button click method
NSString *soundPath = [[NSBundle mainBundle] pathForResource:#"sound1" ofType:#"mp3"];
NSURL *soundUrl = [NSURL fileURLWithPath:soundPath];
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithURL:soundUrl];
[player play];
but i get the above error.Any help would be appreciated.
It's "initWithContentsOfURL:" not "initWithURL:".
As in:
AVAudioPlayer *player = [[AVAudioPlayer alloc]
initWithContentsOfURL:soundUrl];

Dynamic video playback speed on iOS? [duplicate]

I'm wondering if it's possible to change the video playback speed in an iphone application. we want users to yell in the microphone to speed up the playback and get to the end.
You have to use setCurrentPlaybackRate:
There is a rate property for the AVPlayer.
If you take the example from Apple called "avPlayerDemo" in the resource section, you then simply have to set the mplayer.rate. It worked for me, I created a new slider in the xib files, implemented that slider in the AVPlayerDemoPlaybackViewController and simply set mPlayer.rate to the slider value.
What about the MPMoviePlayerController?
setCurrentPlaybackRate
Here's some code which does not work at that spot
-(IBAction)abspielen:(id)sender
{
NSString *titleOfButton = [sender titleForState:UIControlStateNormal];
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:titleOfButton ofType:#"mov"];
NSURL *movieURL = [ NSURL fileURLWithPath:moviePath];
MPMoviePlayerController *themovie = [[MPMoviePlayerController alloc]initWithContentURL: movieURL];
[themovie play];
[themovie setCurrentPlaybackRate:2.f];
[themovie release];
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
[moviePlayer release];
}

How to change the speed of video playback

I'm wondering if it's possible to change the video playback speed in an iphone application. we want users to yell in the microphone to speed up the playback and get to the end.
You have to use setCurrentPlaybackRate:
There is a rate property for the AVPlayer.
If you take the example from Apple called "avPlayerDemo" in the resource section, you then simply have to set the mplayer.rate. It worked for me, I created a new slider in the xib files, implemented that slider in the AVPlayerDemoPlaybackViewController and simply set mPlayer.rate to the slider value.
What about the MPMoviePlayerController?
setCurrentPlaybackRate
Here's some code which does not work at that spot
-(IBAction)abspielen:(id)sender
{
NSString *titleOfButton = [sender titleForState:UIControlStateNormal];
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:titleOfButton ofType:#"mov"];
NSURL *movieURL = [ NSURL fileURLWithPath:moviePath];
MPMoviePlayerController *themovie = [[MPMoviePlayerController alloc]initWithContentURL: movieURL];
[themovie play];
[themovie setCurrentPlaybackRate:2.f];
[themovie release];
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
[moviePlayer release];
}

Resources