2013-04-16 6 views
1

Я играю аудио в приложении iphone, но проблема в том, что он отлично работает на симуляторе, но он не работает на устройстве, вот мой код, он просто закрывает приложение, когда этот код пробеги.Аудиофайл не работает на устройстве, но работает на симуляторе

  NSString*thePath=[[NSBundle mainBundle] pathForResource:fileName ofType:@"MP3"]; 
    NSURL*url=[NSURL fileURLWithPath:thePath]; 



    //NSURL *url = [NSURL URLWithString:@"http://celeritas-solutions.com/pah_brd_v1/productivo/1.mp3"]; 
    mp = [[MPMoviePlayerViewController alloc] initWithContentURL:url]; 
    [[mp moviePlayer] prepareToPlay]; 
    [[mp moviePlayer] setUseApplicationAudioSession:NO]; 
    [[mp moviePlayer] setShouldAutoplay:YES]; 
    [[mp moviePlayer] setControlStyle:2]; 
    [[mp moviePlayer] setRepeatMode:MPMovieRepeatModeOne]; 
    [self presentMoviePlayerViewControllerAnimated:mp]; 

Вот код видео это также работает на тренажере, но не на Iphone

  NSString*thePath=[[NSBundle mainBundle] pathForResource:fileName ofType:@"MP4"]; 
    NSURL*url=[NSURL fileURLWithPath:thePath]; 
    //NSURL *url = [NSURL URLWithString:@"http://celeritas-solutions.com/pah_brd_v1/productivo/1.mp4"]; 
    mp = [[MPMoviePlayerViewController alloc] initWithContentURL:url]; 
    [[mp moviePlayer] prepareToPlay]; 
    [[mp moviePlayer] setUseApplicationAudioSession:NO]; 
    [[mp moviePlayer] setShouldAutoplay:YES]; 
    [[mp moviePlayer] setControlStyle:2]; 
    [[mp moviePlayer] setRepeatMode:MPMovieRepeatModeOne]; 
    [self presentMoviePlayerViewControllerAnimated:mp]; 

ответ

0

попробовать этот код ...

NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"mp3"]; 
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL]; 
theAudio.delegate=self; 
[theAudio play]; 

сначала проверьте файл хранится в вашем проекте папке или нет, а также эта переменная не является nil.

также проверить ссылку play-mp3-files-with-iphone-sdk

И этот учебник how-to-play-audio-and-video-in-iphone

UPDATE:

MPMoviePlayerViewController *Mpplayer =[[MPMoviePlayerViewController alloc] initWithContentURL: [url standardizedURL]]; 
Mpplayer.moviePlayer.movieSourceType = MPMovieSourceTypeUnknown; 
[self presentModalViewController:Mpplayer animated:YES]; 
[[Mpplayer moviePlayer] play]; 
+0

, но это не покажет игроку, как это показано в mpmovieplayer –

+0

@JdeveloperIphone о порядке чувак тогда смотрите по этой ссылке .. Http: //stackoverflow.com/questions/2058067/i-have-a-problem-with-mpmovieplayercontroller-iphone-sdk –

+0

@JdeveloperIphone также проверяет этот учебник. http://iphoneapp-dev.blogspot.in/2011/07/ how-to-play-audio-and-video-in-iphone.html Я надеюсь, что это вам полезно .. :) –

3

Сначала добавьте AVFoundation.framework и добавьте ниже код.

в файле .h

#import <AVFoundation/AVFoundation.h> 

и .m файл

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; 
+0

ya его работа .... Thx ... :) –

+1

wc @ KaushikMovaliya –

Смежные вопросы