AVPlayer is Not Playing From NSCachesDirectory? - iphone

Hi I am Trying to Play Video Files From NSCachesDirectory. The Player is not loading the Files from NSCachesDirectory in videoView layer.
Is it Possible to play Video from cacheDirectory Memory?
Please suggest me...
I have tried this..
NSArray *myPathList = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachesDir = [myPathList objectAtIndex:0];
NSString *songPath = [[NSString alloc] initWithString: [cachesDir stringByAppendingPathComponent:[NSString stringWithFormat:#"Song.%#", downloadURL]]];
NSURL *pathurl = [[NSURL alloc] initFileURLWithPath:songPath];
NSLog(#"--pathurl---%#",pathurl);
avPlayer =[AVPlayer playerWithURL:pathurl];
self.avPlayerLayer =[AVPlayerLayer playerLayerWithPlayer:avPlayer];
if ( !([avPlayer status] == AVPlayerStatusReadyToPlay) && (dataReceivedSoFar.length >10000))
{
avPlayerLayer.frame =CGRectMake(0, 0, 320, 450);
[[self.videoView layer] addSublayer:avPlayerLayer];
[avPlayer play];
NSLog(#"Video IS Playing");
[alert dismissWithClickedButtonIndex:0 animated:YES];
}

KVO approach.
Add observer:
self.player = [AVPlayer playerWithURL:url];
[self.player addObserver:self forKeyPath:#"status" options:0 context:&PlayerStatusContext];
Observing value
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context {
if (context == &PlayerStatusContext) {
AVPlayer *thePlayer = (AVPlayer *)object;
if ([thePlayer status] == AVPlayerStatusFailed) {
NSError *error = [self.player error];
// Respond to error: for example, display an alert sheet.
return;
}
// Deal with other status change if appropriate.
if ([thePlayer status] == AVPlayerStatusReadyToPlay) {
[self play];
}
}
// Deal with other change notifications if appropriate.
[super observeValueForKeyPath:keyPath ofObject:object
change:change context:context];
return;
}
Playing:
- (IBAction)play:sender {
[self.player play];
}
EDITING:
As awolCZ said AVPlayer can not play partially downloaded files. But you could use something like http://test.com/test.mp3 for URL.

I'm not sure that [avPlayer status] == AVPlayerStatusReadyToPlay returns YES in this case. It takes some time for AVPlayer to load the item. You should can play immediately even if it's better way to track AVPlayer.status using KVO.
Lukas
EDIT: Try it this way (quick win):
NSArray *myPathList = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachesDir = [myPathList objectAtIndex:0];
NSString *songPath = [[NSString alloc] initWithString: [cachesDir stringByAppendingPathComponent:[NSString stringWithFormat:#"Song.%#", downloadURL]]];
NSURL *pathurl = [[NSURL alloc] initFileURLWithPath:songPath];
NSLog(#"--pathurl---%#",pathurl);
avPlayer =[AVPlayer playerWithURL:pathurl];
self.avPlayerLayer =[AVPlayerLayer playerLayerWithPlayer:avPlayer];
avPlayerLayer.frame =CGRectMake(0, 0, 320, 450);
[[self.videoView layer] addSublayer:avPlayerLayer];
[avPlayer play];

Related

Play recorded video using UIImagePickerController

I am creating an app which will record a video using UIImagePickerController and I am saving the recorded video in documents directory and trying to play back the video on click of USE (want to show the full first frame of recorded video along with play button in the middle like the native application of iPhone).
I am able to record the video and save it into document directory but unable to create the frame and playback.
I tried to move on new class where I can play the recorded video but gets crashed on click of USE button.
Here is my code
-(void)btnRecord_Press
{
BOOL canRecordVideo;
canRecordVideo = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
if (canRecordVideo)
{
UIImagePickerController *videoRecorder = [[UIImagePickerController alloc]init];
videoRecorder.sourceType = UIImagePickerControllerSourceTypeCamera;
videoRecorder.delegate=self;
videoRecorder.showsCameraControls = TRUE;
NSArray *mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
NSArray *videoMediaTypesOnly = [mediaTypes filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:#"(SELF CONTAINS %#)",#"movie"]];
BOOL movieOuputPossible = (videoMediaTypesOnly!=nil);
if (movieOuputPossible)
{
videoRecorder.mediaTypes = videoMediaTypesOnly;
[self presentViewController:videoRecorder animated:YES completion:nil];
}
}
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSData *videoData = [NSData dataWithContentsOfURL:videoURL];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *tempPath = [documentsDirectory stringByAppendingFormat:#"/vid1.mp4"];
BOOL success = [videoData writeToFile:tempPath atomically:NO];
[self dismissViewControllerAnimated:NO completion:nil];
PlayMovie *play = [[PlayMovie alloc]initWithNibName:#"PlayMovie" bundle:Nil];
[self.navigationController pushViewController:play animated:YES];
}
Any help would be appreciable.
Thanks
I did this using this code.
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
[self dismissViewControllerAnimated:NO completion:nil];
[self Play];
}
-(void)Play
{
NSData *videoData = [NSData dataWithContentsOfURL:videoURL];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *tempPath = [documentsDirectory stringByAppendingFormat:#"/vid1.mp4"];
BOOL success = [videoData writeToFile:tempPath atomically:NO];
player = [[MPMoviePlayerController alloc]initWithContentURL:videoURL];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(btnDone_Press) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
self._player.shouldAutoplay = NO;
UIImage *thumbnail = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
screenSize = [[UIScreen mainScreen]bounds].size;
if (screenSize.height >480.0f)
{
player.view.frame = CGRectMake(0, 0, 320, 548);
}
else
{
player.view.frame = CGRectMake(0, 0, 320, 460);
}
}
[self.view addSubview:player.view];
self._player.scalingMode = MPMovieScalingModeAspectFit;
self._player.fullscreen = YES;
[self._player play];
}

How to record video of app screen

I have created a streaming video app. and now i want to record that video which is playing in MPVideoPlayer,also its sound. I have tried this code. but this code is only record black screen and no sound. I am adding MPVideoPlayer instance dynamically. so , plz help me to do this any source code or library will be great help.
Try this :
.h file
import MediaPlayer/MediaPlayer.h
NSString *strSelectedVideoPath;
MPMoviePlayerController *player
#property (nonatomic,retain) NSString *strSelectedVideoPath;
#property (nonatomic,retain) MPMoviePlayerController *player;
.m file
-(void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:strSelectedVideoPath]];
player.scalingMode = MPMovieScalingModeFill;
player.movieSourceType = MPMovieSourceTypeFile;
player.view.frame = CGRectMake(0, 45, 320, 400);
player.shouldAutoplay = YES;
[player prepareToPlay];
[self.view addSubview:player.view];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:player];
[player play];
}
- (void) movieFinishedCallback:(NSNotification*) aNotification {
MPMoviePlayerController *player1 = [aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player1];
[player1.view removeFromSuperview];
player1 = nil;
}
You have to add MediaPlayer.framework
For Record video :
-(void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info {
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
[self dismissModalViewControllerAnimated:NO];
if (CFStringCompare ((CFStringRef) mediaType, kUTTypeMovie, 0)
== kCFCompareEqualTo) {
NSString *moviePath = [[info objectForKey: UIImagePickerControllerMediaURL] path];
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
UISaveVideoAtPathToSavedPhotosAlbum (moviePath,self,#selector(video:didFinishSavingWithError:contextInfo:), nil);
}
}
}
- (void)video:(NSString*)videoPath didFinishSavingWithError:(NSError*)error contextInfo:(void*)contextInfo {
if (error) {
}
else{
NSURL *videoURl = [NSURL fileURLWithPath:videoPath];
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURl options:nil];
AVAssetImageGenerator *generate = [[AVAssetImageGenerator alloc] initWithAsset:asset];
generate.appliesPreferredTrackTransform = YES;
NSError *err = NULL;
//For Thumb Image
CMTime time = CMTimeMake(1, 60);
CGImageRef imgRef = [generate copyCGImageAtTime:time actualTime:NULL error:&err];
self.strUploadVideoPath = videoPath;
CGImageRelease(imgRef);
[generate release];
[asset release];
}
}

No audio played using MPMoviePlayerController

I have been using MPMoviePlayerController to play mp4 file. Video is playing fine but there is no audio at all.
I have downloaded first in one function and played using another. Please check the code below. Am I doing anything wrong here...
- (void) download_file : (NSString *) msg_url
{
if (msg_url != nil) {
// Download and play
NSURL *url = [NSURL URLWithString:msg_url];
NSData *urlData = [NSData dataWithContentsOfURL:url];
if ( urlData )
{
char file_path[512] = {0};
get_app_data_path(OFI_VC_MAILBOX_PATH, file_path); // Give document path.
NSString *filePath = [NSString stringWithFormat:#"%s/%#", file_path,#"mailbox.mp4"];
[urlData writeToFile:filePath atomically:YES];
[self performSelectorOnMainThread:#selector(play_mp4_file:) withObject:filePath waitUntilDone:NO];
}
}
}
- (void) play_mp4_file : (NSString *) filepath
{
if (is_same_view == true) {
[self.view setUserInteractionEnabled:YES];
if (filepath != nil) {
NSURL *file_url = [NSURL fileURLWithPath:filepath];
moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:file_url];
moviePlayer.controlStyle = MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay = YES;
moviePlayer.useApplicationAudioSession = YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
}
}
}
Thanks for your helps
I have fixed the issue. Problem is with .mp4 extension, I have used .mov. Its playing audio now.

MPMoviePlayerController Causes All Other Audio To Be Soft (After MP finishes)

I have an app that plays some background music, when a certain button is pushed, it pushes a new view using the navigation controller. That new view has a MPMoviePlayerController and an AVCaptureSession with a shared AudioSession. After that view is dismissed, the sound in the background is really soft compared to how it was. What is it that is causing the volume to be so subdued after playing?
NSError* error4 = nil;
AVAudioSession* audioSession = [AVAudioSession sharedInstance];
if (![audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&error4]) {
NSLog(#"AVAudioSession setCategory failed: %#", [error4 localizedDescription]);
}
// Set audio session property "allow mixing" to true so audio can be recorded while it is playing
UInt32 allowMixing = true;
OSStatus status = AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(allowMixing), &allowMixing);
if (status != kAudioSessionNoError) {
NSLog(#"AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers) failed: %ld", status);
}
// Activate the audio session
error4 = nil;
if (![audioSession setActive:YES error:&error4]) {
NSLog(#"AVAudioSession setActive:YES failed: %#", [error4 localizedDescription]);
}
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [paths objectAtIndex:0];
NSString *proud = [[documentsDirectoryPath stringByAppendingPathComponent:#"imissyou"] stringByAppendingPathComponent:selectedCountry];
NSURL *movieURL = [[NSURL fileURLWithPath:proud] retain];
player =
[[MPMoviePlayerController alloc] initWithContentURL: movieURL];
player.useApplicationAudioSession=YES;
[player prepareToPlay];
player.controlStyle = MPMovieControlStyleNone;
player.allowsAirPlay = NO;
player.scalingMode = MPMovieScalingModeFill;
player.view.frame = self.view.frame;
[self.view insertSubview:player.view belowSubview:vImagePreview];
[player setFullscreen:YES animated:YES];
// ...
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(exitedFullscreen:) name:MPMoviePlayerDidExitFullscreenNotification object:player];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayerWillExitFullscreen:)
name:MPMoviePlayerWillExitFullscreenNotification
object:player];
[player play];
session = [[AVCaptureSession alloc] init];
[session beginConfiguration];
session.sessionPreset = AVCaptureSessionPresetMedium;
CALayer *viewLayer = self.vImagePreview.layer;
NSLog(#"viewLayer = %#", viewLayer);
AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
captureVideoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
captureVideoPreviewLayer.frame = self.vImagePreview.bounds;
[captureVideoPreviewLayer setCornerRadius:14];
[captureVideoPreviewLayer setBorderWidth:3.0];
[captureVideoPreviewLayer setBorderColor:[[UIColor whiteColor] CGColor]];
[[vImagePreview layer] setCornerRadius:14];
[[vImagePreview layer] setBorderWidth:3.0];
[[vImagePreview layer] setBorderColor:[[UIColor whiteColor] CGColor]];
[self.vImagePreview.layer addSublayer:captureVideoPreviewLayer];
[captureVideoPreviewLayer release];
AVCaptureDevice *device = [self frontFacingCameraIfAvailable];
NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
if (!input) {
// Handle the error appropriately.
NSLog(#"ERROR: trying to open camera: %#", error);
}
AVCaptureDevice *audioCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
NSError *error2 = nil;
AVCaptureDeviceInput *audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audioCaptureDevice error:&error2];
AVCaptureMovieFileOutput *movieFileOutput = [[AVCaptureMovieFileOutput alloc] init];
NSString *archives = [documentsDirectoryPath stringByAppendingPathComponent:#"archives"];
NSString *editedfilename = [[selectedCountry lastPathComponent] stringByDeletingPathExtension];
NSString *datestring = [[editedfilename stringByAppendingString:#" "] stringByAppendingString:currentTime];
NSLog(#"%#", datestring);
NSString *outputpathofmovie = [[archives stringByAppendingPathComponent:datestring] stringByAppendingString:#".mp4"];
NSURL *outputURL = [[NSURL alloc] initFileURLWithPath:outputpathofmovie];
[session addInput:input];
[session addInput:audioInput];
[session addOutput:movieFileOutput];
[session commitConfiguration];
[session startRunning];
[movieFileOutput startRecordingToOutputFileURL:outputURL recordingDelegate:self];
[movieURL release];
[outputURL release];
The audio session may be "ducking" the background music. You might want to set the property "kAudioSessionProperty_OtherMixableAudioShouldDuck" to false to disable that.
I got it figured out now. I had category set to PlayAndRecord. I changed it to Ambient (which also allows to record audio while playing audio) and removed property of OverrideCategoryMixWithOthers, leaving just
OSStatus propertySetError = 0;
UInt32 allowMixing = true;
propertySetError |= AudioSessionSetProperty(kAudioSessionProperty_OtherMixableAudioShouldDuck, sizeof(allowMixing), &allowMixing);

AVPlayer And Local Files

I am building a MP3 player for iOS that plays audio files hosted on the web. I want to offer the ability to play the files offline so I have the files downloading using ASIHTTP but I am cannot seem to find info on initiallzing AVPlayer with a mp3 in the app documents directory. Has anyone done this before? Is it even possible?
*I posted an answer below that shows how to use the iOS AvPlayer for both local and http files. Hope this helps!
I decided to answer my own question because I felt like there is very little documentation on how to use the Apple provided AVPlayer for both local and stream (over http) files. To help understand the solution, I put together a sample project on GitHub in Objective-C and Swift The code below is Objective-C but you can download my Swift example to see that. It is very similar!
What I found is that the two ways of setting up the files are almost identical except for how you instantiate your NSURL for the Asset > PlayerItem > AVPlayer chain.
Here is an outline of the core methods
.h file (partial code)
-(IBAction) BtnGoClick:(id)sender;
-(IBAction) BtnGoLocalClick:(id)sender;
-(IBAction) BtnPlay:(id)sender;
-(IBAction) BtnPause:(id)sender;
-(void) setupAVPlayerForURL: (NSURL*) url;
.m file (partial code)
-(IBAction) BtnGoClick:(id)sender {
NSURL *url = [[NSURL alloc] initWithString:#""];
[self setupAVPlayerForURL:url];
}
-(IBAction) BtnGoLocalClick:(id)sender {
// - - - Pull media from documents folder
//NSString* saveFileName = #"MyAudio.mp3";
//NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//NSString *documentsDirectory = [paths objectAtIndex:0];
//NSString *path = [documentsDirectory stringByAppendingPathComponent:saveFileName];
// - - -
// - - - Pull media from resources folder
NSString *path = [[NSBundle mainBundle] pathForResource:#"MyAudio" ofType:#"mp3"];
// - - -
NSURL *url = [[NSURL alloc] initFileURLWithPath: path];
[self setupAVPlayerForURL:url];
}
-(void) setupAVPlayerForURL: (NSURL*) url {
AVAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
AVPlayerItem *anItem = [AVPlayerItem playerItemWithAsset:asset];
player = [AVPlayer playerWithPlayerItem:anItem];
[player addObserver:self forKeyPath:#"status" options:0 context:nil];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if (object == player && [keyPath isEqualToString:#"status"]) {
if (player.status == AVPlayerStatusFailed) {
NSLog(#"AVPlayer Failed");
} else if (player.status == AVPlayerStatusReadyToPlay) {
NSLog(#"AVPlayer Ready to Play");
} else if (player.status == AVPlayerItemStatusUnknown) {
NSLog(#"AVPlayer Unknown");
}
}
}
-(IBAction) BtnPlay:(id)sender {
[player play];
}
-(IBAction) BtnPause:(id)sender {
[player pause];
}
Check out the Objective-C source code for a working example of this.
Hope this helps!
-Update 12/7/2015 I now have a Swift example of the source code you can view here.
I got AVPlayer to work with local URL by prepending file:// to my local url
NSURL * localURL = [NSURL URLWithString:[#"file://" stringByAppendingString:YOUR_LOCAL_URL]];
AVPlayer * player = [[AVPlayer alloc] initWithURL:localURL];
Yes,thats possible to download and save the .mp3(or any kind of file)into NSDocument directory and then you can retrive from that and play by using AVAudioPlayer.
NSString *downloadURL=**your url to download .mp3 file**
NSURL *url = [NSURLURLWithString:downloadURL];
NSURLConnectionalloc *downloadFileConnection = [[[NSURLConnectionalloc] initWithRequest: [NSURLRequestrequestWithURL:url] delegate:self] autorelease];//initialize NSURLConnection
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *fileDocPath = [NSStringstringWithFormat:#"%#/",docDir];//document directory path
[fileDocPathretain];
NSFileManager *filemanager=[ NSFileManager defaultManager ];
NSError *error;
if([filemanager fileExistsAtPath:fileDocPath])
{
//just check existence of files in document directory
}
NSURLConnection is used to download the content.NSURLConnection Delegate methods are used to support downloading.
(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSFileManager *filemanager=[NSFileManagerdefaultManager];
if(![filemanager fileExistsAtPath:filePath])
{
[[NSFileManagerdefaultManager] createFileAtPath:fileDocPath contents:nil attributes:nil];
}
NSFileHandle *handle = [NSFileHandlefileHandleForWritingAtPath:filePath];
[handle seekToEndOfFile];
[handle writeData:data];
[handle closeFile];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
UIAlertView *alertView=[[UIAlertViewalloc]initWithTitle:#”"message:
[NSStringstringWithFormat:#"Connection failed!\n Error - %# ", [error localizedDescription]] delegate:nilcancelButtonTitle:#”Ok”otherButtonTitles:nil];
[alertView show];
[alertView release];
[downloadFileConnectioncancel];//cancel downloding
}
Retrieve the downloaded Audio and Play:
NSString *docDir1 = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *myfilepath = [docDir1 stringByAppendingPathComponent:YourAudioNameinNSDOCDir];
NSLog(#”url:%#”,myfilepath);
NSURL *AudioURL = [[[NSURLalloc]initFileURLWithPath:myfilepath]autorelease];
Just write your code to play Audio by using AudioURL
I Like to know if u have any clarification in this regard.
Thank you
Try this
NSString*thePath=[[NSBundle mainBundle] pathForResource:#"yourVideo" ofType:#"MOV"];
NSURL*theurl=[NSURL fileURLWithPath:thePath];
Swift local playback version, assuming I have a file "shelter.mp3" in my bundle:
#IBAction func button(_ sender: Any?) {
guard let url = Bundle.main.url(forResource: "shelter", withExtension: "mp3") else {
return
}
let player = AVPlayer(url: url)
player.play()
playerView?.player = player;
}
See here for details about playerView or playing a remote url.
its very difficult to play a song using a Avplayer why you are not use a MPMoviePlayerController player . i have play song from document directory .i am posting a code pls refer this .its working fine .and also u directly from url live .
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *publicDocumentsDir = [paths objectAtIndex:0];
NSString *dataPath = [publicDocumentsDir stringByAppendingPathComponent:#"Ringtone"];
NSString *fullPath = [dataPath stringByAppendingPathComponent:[obj.DownloadArray objectAtIndex:obj.tagvalue]];
[[UIApplication sharedApplication] setStatusBarHidden:NO animated:NO];
NSURL *url = [NSURL fileURLWithPath:fullPath];
videoPlayer =[[MPMoviePlayerController alloc] initWithContentURL: url];
[[videoPlayer view] setFrame: [self.view bounds]];
[vvideo addSubview: [videoPlayer view]];
videoPlayer.view.frame=CGRectMake(0, 0,260, 100);
videoPlayer.view.backgroundColor=[UIColor clearColor];
videoPlayer.controlStyle = MPMovieControlStyleFullscreen;
videoPlayer.shouldAutoplay = YES;
[videoPlayer play];
videoPlayer.repeatMode=YES;
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self selector:#selector(moviePlayerEvent:) name:MPMoviePlayerLoadStateDidChangeNotification object:videoPlayer];
/* NSNotificationCenter *notificationCenter1 = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self selector:#selector(moviePlayerEvent1:) name:MPMoviePlaybackStateStopped object:videoPlayer];
*/
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(playbackStateChange:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:videoPlayer];
}
-(void)playbackStateChange:(NSNotification*)notification{
if([[UIApplication sharedApplication]respondsToSelector:#selector(setStatusBarHidden: withAnimation:)])
{
[[UIApplication sharedApplication] setStatusBarHidden:NO
withAnimation:UIStatusBarAnimationNone];
}
else
{
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
}
}
-(void)moviePlayerEvent:(NSNotification*)aNotification{
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:NO];
}
-(void)moviePlayerEvent1:(NSNotification*)aNotification{
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:NO];
}