how to access the files of Nested folders in Skydrive API? - objective-c

NSArray *arr = [[operation.result objectForKey:#"data"] valueForKey:#"name"];
NSArray *arrId = [[operation.result objectForKey:#"data"] valueForKey:#"id"];
NSArray *folder=[[operation.result objectForKey:#"data"]valueForKey:#"type"];
[dictDocument setObject:arrId forKey:#"ID"];
[dictDocument setObject:arr forKey:#"Name"];
[dictDocument setObject:folder forKey:#"type"];
Arrid===>folder.id,file.id
arr===>filename
folder====>type of file Eg.Folder,audio,video
I can't able to access the files of nested folders??

try like this,and once check in copy bundle identifiers files are added succeessfully or not.
NSString *filepath = [[NSBundle mainBundle] pathForResource:#"vid" ofType:#"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
avPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:fileURL error:nil];
avPlayer.delegate = self;
[avPlayer prepareToPlay];
[avPlayer play];
FOR PLAYING VEDIO
You can use MPMoviePlayerController to play local file.
refer this one for playing vedio file.

Related

Playing a sound file in a cordova plugin in Objective C

I have created a cordova plugin which has some wav files. These are in Plugins folder. I'm trying to play a sound but I don't where is the location of the file I'm looking for within the project. The code I'm using is the following:
NSString * sourcePath = #"Where?";
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:soundFilePath]){
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
NSError *error = nil;
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:&error];
player.numberOfLoops = -1; //Infinite
[player play];
}
I have tried different locations such as:
NSString *soundFilePath = [NSString stringWithFormat:#"%#/mywavfile.wav",[[NSBundle mainBundle] resourcePath]]
NSString *soundFilePath = [NSString stringWithFormat:#"%#/Plugins/cordova.plugin/mywavfile.wav",[[NSBundle mainBundle] resourcePath]]
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:#"mywavfile" ofType:#"wav"];
Any recommendations?
I found a solution to expose the folder in www foder. In config.xml I used the cordova plugin command
<asset src="www/sounds/myfile.m4a" target="sounds/myfile.m4a"/>
And the file exists in www/sounds/myfile.m4a folder.

Unable to convert a string to a NSURL

I am trying to turn off WAL in CoreData using this code:
// Code to disable journaling mode
NSString *applicationDocumentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *urlString = [applicationDocumentsDirectory stringByAppendingPathComponent: #"saori.sqlite"];
NSURL *url = [[NSURL alloc] initWithString:urlString];
NSDictionary *options = #{NSSQLitePragmasOption:#{#"journal_mode":#"DELETE"}};
NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] init];
[psc addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:url options:options error:nil];
This is my NSString that I need to convert to a URL:
/Users/rolfmarsh/Library/Application Support/iPhone Simulator/7.1/Applications/7A614C51-AC51-4F5B-9716-6E3D2F160324/Documents/saori.sqlite
When I use that string in this statement, it generates nil.
NSURL *url = [[NSURL alloc] initWithString:urlString];
I don't see anything wrong with the string. What am I doing wrong?
Read the docs for NSURL. You have a file path and you need to create a file URL from the file path.
NSURL *url = [NSURL fileURLWithPath:urlString];

loading AVAudioPlayer file URLs from a Plist

I'm working with about 50 AVAudioPlayers that each load a separate audio file. The files are fixed and within the app bundle. They are triggered by events later on in the app. Currently I'm hardcoding the creation of each player instance, like so:
//No01
NSURL *no01URL = [[NSURL alloc] initFileURLWithPath: [[NSBundle mainBundle] pathForResource:#"audio1" ofType:#"aiff"]];
self.no01Player = [[AVAudioPlayer alloc] initWithContentsOfURL:no01URL error:nil];
no01Player.numberOfLoops = 0;
no01Player.volume = 0;
no01Player.delegate = self;
//No02
NSURL *no02URL = [[NSURL alloc] initFileURLWithPath: [[NSBundle mainBundle] pathForResource:#"audio2" ofType:#"aiff"]];
self.no02Player = [[AVAudioPlayer alloc] initWithContentsOfURL:no02URL error:nil];
no02Player.numberOfLoops = 0;
no02Player.volume = 0;
no02Player.delegate = self;
//No03 and so on...
Obviously this is labourious and bad coding practice. I'd like to instead have the list of files in a Plist and load these into variables that populate just one example of the above code. I'd like to learn how to be DRY with this but have limited experience of loading data from Plists, arrays, dictionaries, etc.
Any help is appreciated, even if it is to point me in the direction of a relevant tutorial.
Thank you.
You can simply place the audio file names in text file using 'new line' separator. And read the file and store the names in an array. To create the URL take the file names dynamically from array as given below
// Read description from text file
NSBundle *audioBundle = [NSBundle mainBundle];
NSString *audioPath = [audioBundle pathForResource:audioFileNames ofType:#"txt"];
NSString *audioContent = [NSString stringWithContentsOfFile:audioPath encoding:NSUTF8StringEncoding error:nil];
// ===========Make an array using audioContent=============
NSArray *audioFiles = [audioContent componentsSeparatedByString:#"\n"];
Use the array to get file names :
NSURL *no01URL = [[NSURL alloc] initFileURLWithPath: [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:#"%#",[audioFiles objectAtIndex:audioCount]] ofType:#"aiff"]];
If your file names are like audio1,audio2.. no need of using all these. Just change in URL like :
NSURL *no01URL = [[NSURL alloc] initFileURLWithPath: [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:#"audio%d",audioCount] ofType:#"aiff"]];
OK for anyone else needing to do this, here's what I ended up with:
//Load location data from Plist file into an Array
NSString *path = [[NSBundle mainBundle] pathForResource:#"Audionodes" ofType:#"plist"];
locationArray = [[NSArray alloc] initWithContentsOfFile:path];
// Create AVAudioPlayers for this view
self.audioPlayerArray = [[NSMutableArray alloc] init];
for (int i = 0; i < [locationArray count]; i++) {
NSString *filename = [[locationArray objectAtIndex:i] valueForKey:#"filename"];
NSString *filetype = [[locationArray objectAtIndex:i] valueForKey:#"filetype"];
int loops = [[[locationArray objectAtIndex:i] valueForKey:#"loops"] intValue];
NSURL *url = [[NSURL alloc]initFileURLWithPath:[[NSBundle mainBundle] pathForResource:filename ofType:filetype]];
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
player.delegate = self;
player.numberOfLoops = loops;
player.volume = 0;
[self.audioPlayerArray addObject:player];
[url release];
[player release];
}
Putting the generated players in audioPlayerArray means I can get at them later.

AVAudioPlayer doesn't work with (NSString *)filename

I want to implement a player that plays sounds and/or music. I have these two methods:
-(void)playSound:(int)soundIndex
{
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[SoundFxFilenameArray objectAtIndex:soundIndex] ofType:#"mp3"]];
if(FxPlayer)
{
[FxPlayer release];
FxPlayer = nil;
}
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategorySoloAmbient error:nil];
FxPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
[FxPlayer play];
}
-(void)playMusic:(NSString *)filename
{
NSURL *url = [NSURL URLWithString:[[NSBundle mainBundle] pathForResource:filename ofType:#"mp3"]];
if(MusicPlayer)
{
[MusicPlayer release];
MusicPlayer = nil;
}
MusicPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
[MusicPlayer play];
}
Now, [[SoundPlayer sharedManager] playSound:FXIndex_Default] works just fine. When I try to play music though, [[SoundPlayer sharedManager] playMusic:#"music_file_name_here" just doesn't do anything. Note that both the sound file and the music file are of the same format (mp3).
Also, the "sharedInstance" is because I implemented the singleton pattern for this audio player.
Any pointers or ideas on what is so wrong in my code so that I can play sounds but not music?
Use fileURLWithPath instead of URLWithString in playMusic:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:filename ofType:#"mp3"]];
URLWithString expects a complete URL such as "file://path/to/file.mp3" as argument, fileURLWithPath expects just a file path.

How to play system button click sound on iPad?

I need to play some system sound when users click button in my application which is running on iPad. How to implement it in iOS?
If you want to play a short sound (shorter than 30 sec), you can do it easily like this:
Note: You'll have to add AudioToolbox framework and import it (#import <AudioToolbox/AudioToolbox.h>)
SystemSoundID mySSID;
NSString *path = [[NSBundle mainBundle] pathForResource:#"beep" ofType:#"wav"];
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath: path], &mySSID);
AudioServicesPlaySystemSound(mySSID);
Also note that the file can be:
No longer than 30 seconds in duration
In linear PCM or IMA4 (IMA/ADPCM) format
Packaged in a .caf, .aif, or .wav file
You should use AVAudioPlayer.
There's a great tutorial here on using AVAudioPlayer to play sounds. A very simple example of it's use:
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:#"%#/audiofile.mp3",dataPath];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
if (audioPlayer == nil)
NSLog([error description]);
else
[audioPlayer play];
NSString *path = [[NSBundle mainBundle] pathForResource:#"gorilla 2" ofType:#"mp3"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
[theAudio play];