Domanda

I used this code to play songs it is not playing the songs inside the folders or folders of folders except the Documents directory.

NSString *songname=[NSString stringWithFormat:@"%@",songArray[songIndex]];
NSLog(@"songname:%@",songname);

NSString* saveFileName = songname;

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:saveFileName];
NSURL *url = [[NSURL alloc] initFileURLWithPath: path];
self.audioPlayer=[[AVAudioPlayer alloc] initWithContentsOfURL:url error:NULL];
È stato utile?

Soluzione

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"github.mp4"];
NSURL *url1 = [[NSURL alloc] initFileURLWithPath: path];
avPlayer = [AVPlayer playerWithURL:url1] ;
[self.avplayer play];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top