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.
Related
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.
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'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.
I'm trying to play an mp3 in a Mac Application in Xcode 4.2. How would I do this?
You are not giving us much to work with...
If you just want a simple sound, use NSSound:
NSString *resourcePath = [[NSBundle mainBundle] pathForResource:#"fn" ofType:#"mp3"];
NSSound *sound = [[NSSound alloc] initWithContentsOfFile:resourcePath byReference:YES];
[sound play];
// wait for the sound to play before you release these...
With NSSound, the sound plays concurrently with your code. A common mistake is to release the sound or resource while it is still playing. Don't do that.
You can also use QTMovie in QTKit:
NSError *err = nil;
QTMovie *sound = [[QTMovie movieWithFile:#"fn.mp3" error:&err] retain];
[sound play];
For more demanding sounds, use CoreAudio
You should use QTKit framework and the QTMovie class.
After save a file I want to open the folder of saved file. How do I do that? Thank you very much!
If I understand your question, you want to open the folder into which something was saved in the Finder?
This should do the trick -- it assumes that you have a reference to the savePanel.
NSURL *fileURL = [savePanel URL];
NSURL *folderURL = [fileURL URLByDeletingLastPathComponent];
[[NSWorkspace sharedWorkspace] openURL: folderURL];
If you are starting with an NSString containing the path, then start with:
NSURL *fileURL = [NSURL fileURLWithPath: stringContainingPath];
Even better would be to not just open the folder, but have the saved file selected. NSWorkspace can do that for you:
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:
#[ URLToSavedFile ]];
The argument is an array of URLs, so if you have only one file you want to reveal, you simply pass an array of one object.
If, for some reason, you're targeting a version of Mac OS X older than 10.6, you'd use the older path-based method instead:
[[NSWorkspace sharedWorkspace] selectFile:pathToSavedFile
inFileViewerRootedAtPath:#""];
(You want to pass an empty string for the second argument so that the Finder will reuse an existing Finder window for the folder, if there is one.)
I know this post is fairly old, but with 10.9 what you want to do is
NSString* folder = #"/path/to/folder"
[[NSWorkspace sharedWorkspace]openFile:folder withApplication:#"Finder"];