I am using MPMoviePlayerController to play video on iOS.
First time I hit the url and video gets downloaded to documents directory & played well.
Second time I check if the video is already downloaded or not.
If not then it goes to server & download it,
if yes then it should access it from documents directory and should play video.
but when I fetch video from documents directory then it shows the path well, along with video file name, but
it doesn't play the video.
Directly it moves to last view with blank white screen.
What I am doing wrong.
Thanks in advance.
Here is my code.
NSArray *arrayPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *docDir = [arrayPaths objectAtIndex:0];
NSString* destinationDirectoryPath=docDir;
NSString *clientPathString = [[NSString alloc] initWithFormat:#"/user"];
destinationDirectoryPath = [destinationDirectoryPath stringByAppendingString:clientPathString];
destinationDirectoryPath = [destinationDirectoryPath stringByAppendingString:#"/video1/"];
NSString *filePath=[NSString stringWithFormat:#"%#",userVideoDTO.learnerid];//#"author";
filePath=[destinationDirectoryPath stringByAppendingString:[NSString stringWithFormat:#"%#.mp4",filePath]];
NSLog(#"FilePath new one :- %#",filePath);
self.url = [NSURL fileURLWithPath:filePath];
Then this self.url is passed to MPMoviePlayerController as
self.mp =[[MPMoviePlayerController alloc] initWithContentURL:self.url];
[self.view addSubview:mp.view];
[self.mp play];
What I am missing.
Can anyone let me know.
This same code is working fine on lower versions of iOS. like iOS7 and below.
not on iOS8.
Thanks in advance.
I have been having a similar issue, and it turned out that while in iOS7 and below the containing view controller hadn't had it's -viewWillDisappear:animated: called before the movie player was shown, whereas in iOS8 and going further, it does get called. I was releasing the player and unsubscribing from notifications in -viewWillDisappear:animated:, this time I had to move this code to dealloc.
Related
I were trying to play mp3 song in my iPhone game, I did it! But there is a problem! Now, only that song is able to play in my app, I try changing the name of the song in Xcode but it doesn't work! Then, I deleted that song to try another one, and something extremely weird is happening, Xcode is still running the deleted song! I wanna know how to completely delete that song from my mac and why aren't another songs working.
Here is my delegate.m, I change the (musicamenu) but It just plays the "musicamenu" song. This musicamenu is the song I deleted!
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:#"musicamenu" ofType: #"mp3"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:soundFilePath ];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];
player.numberOfLoops = -1; //infinite loop
[player play];
After deleting the first song and replacing it, do a clean and then try it again. Make sure you did not just delete it from xcode but also removed its reference to the project file in your Mac or wherever you placed it.
I'm writing an online radio streaming app. I'm using my own buttons to control the playback. I really don't want the view of MPMoviePlayerController.
Will apple reject my app if I just let it play the audio without adding MPMoviePlayerController to my view?
I'm thinking of removing second last line in the code below:
player = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[player prepareToPlay];
[player.view setFrame: myView.bounds];
[myView addSubview: player.view]; //i want to remove this line
[player play];
It is also possible to do the following to hide it without removing that line:
player.view.hidden = YES;
I wondering how you would retrieve the path of the file that a user has dragged and dropped into a cocoa application. For example: User drags a file named test from his/her desktop. Then the cocoa application would say: Users/currentusername/Desktop/test
Thanks for the help!
I just downloaded Apple's "CocoaDragAndDrop" sample code and tried it out.
When I drag in a PNG file from the Finder into the running app, the title of the window changes to the path of the image that was dragged in.
Looking inside the sample code, I can see a file URL is included in the Pasteboard:
//if the drag comes from a file, set the window title to the filename
fileURL=[NSURL URLFromPasteboard: [sender draggingPasteboard]];
[[self window] setTitle: fileURL!=NULL ? [fileURL absoluteString] : #"(no name)"];
Try this technique in your own code and modify it for taste.
The accepted answer is no longer working with Xcode 6.
I've found this methode to get the same result:
NSURL*fileURL = [NSURL URLFromPasteboard: [sender draggingPasteboard]];
NSString *filePath = [fileURL path];
[[self window] setTitle:filePath];
Currently working on developing a similar interface, I’ve understood that the OP had asked for path, not URL retrieval. It seems the suggested OS X 10.10 (XCode6) workaround for the accepted answer has issues in refusing to drag and drop content between windows.
However, avoiding declaring NSString *filePath, but simply substituting the [fileURL absoluteString] method with [fileURL path] method in line 175 of DragDropImageView.m of the suggested sample code instead, seems to solve it:
fileURL=[NSURL URLFromPasteboard: [sender draggingPasteboard]];
[[self window] setTitle: fileURL!=NULL ? [fileURL path] : #"(no name)"];
It compiles and runs as devised in Xcode4 through Xcode6, SDK 10.8-10.10, AFAICT.
Hope this can help.
i came across a strange problem, when i add pictures to an past event from web-end,everything is ok,however when i did that from my own iOS app, there's no exception,i just can't see the newly added image.Can't we add photos to the past events from mobile client? Anyone knows that.
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:image,#"source", nil];
[facebookDelegate requestWithGraphPath:[NSString stringWithFormat:#"%#/photos",self.eventID] andParams:params andHttpMethod:#"POST" andDelegate:self];
There's no errors,but i just can't see the uploaded pictures.
And another question, how to set event's profile picture with graph api? I used the following code:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:image,#"picture", nil];
[facebookDelegate requestWithGraphPath:self.eventID andParams:params andHttpMethod:#"POST" andDelegate:self];
It also doesn't work.What's more, i want to konw if we can upload image from web,so we just offer the picture link to facebook ?
thanks.
i think you can try the first one now. It work now
I'm making a soundboard app and I use this code to play mp3 files:
-(IBAction)playSound
{
NSString *path = [[NSBundle mainBundle] pathForResource:#"mysound" ofType:#"mp3"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
[theAudio play];
[theAudio release];
}
When I include [theAudio release]; the sound doesn't play. If I take it out it plays but I don't want to have memory leaks. How can I fix this?
It would be very helpful if you could include whatever code I need to add. I'm new to programming (besides TrueBasic I've used in school) so I'm unfamiliar with Objective-C.
wait til the audio finishes via a delegate to release the audio. I believe there are a number of posts exactly like this on the site if you search, they will have the specific delegate code.
This is only because you use local variable. so theAudio will released immediately.
You should define it as class member and assignment it here. so when this function finished, it still work too.