Note that there are some explanatory texts on larger screens.

plurals
  1. POException with playing audio file by using MPMoviePlayerController
    text
    copied!<p>I used MPMoviePlayerController to play autio in local or url. When I first to play a information,I should download the file and play at the same time.Then the second time ,I can play the information from local if it existed.</p> <p>Now I create a Singleton named PlayController to control autoPlay,play ,pause,stop By manually. If I choose a picture,it will autoplay the file consistent to the picture.If it can not get the playstatus,user should play it by yourself.I can clicked different picture to play the correct audio.</p> <p>The problem I met is that when I clickked a different picture,sometimes the bug will jump as the uploaded screenshot.</p> <p><strong>init the Singleton:</strong></p> <pre><code>-(PlayController*)initWithScenicspot:(ScenicSpot*)sp { pauseimg=[UIImage imageNamed:@"ReadyPlay.png"]; playimg=[UIImage imageNamed:@"ReadyPause.png"]; if (![currentScenicSpot.scenicSpotId isEqualToString:sp.scenicSpotId]) { currentScenicSpot=[sp retain]; self=[super init]; if (self) { if(!pcontroller){ pcontroller = [[MPMoviePlayerController alloc] init]; } [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(loginfo) userInfo:nil repeats:YES]; [self.view setBackgroundColor:[UIColor blueColor]]; detailView=[[DetailView alloc]initWithFrame:[[UIScreen mainScreen] bounds]]; detailView._clickbutton=self; [self.view addSubview:detailView]; self.view.frame=[[UIScreen mainScreen] bounds]; NSURL* ns = nil /*=[HelpTools returnSpotAudioServerPath:sp.scenicSpotId]*/; NSString *audioDiskPath = [HelpTools returnSpotAudioDiskPath:sp.scenicSpotId]; NSString *audioServerPath = [HelpTools returnSpotAudioServerPath:sp.scenicSpotId]; // NSURL* ns = nil; BOOL isNet = NO; if ([HelpTools isFileExist:audioDiskPath]) { ns = [NSURL fileURLWithPath:audioDiskPath]; } else{ ns = [NSURL URLWithString: audioServerPath]; [self downloadAudio:sp.scenicSpotId]; isNet = YES; } [self setContentUrl:ns isNet:isNet]; </code></pre> <p><strong>set the audio path</strong></p> <pre><code>-(void)setContentUrl:(NSURL*)url isNet:(BOOL)isNetData { if (isNetData) { if ([pcontroller respondsToSelector:@selector(loadState)]) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handlePlayback:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil]; [pcontroller setContentURL:url]; [detailView.coloredplaybar setProgress:0 animated:NO]; [pcontroller prepareToPlay]; } else { [detailView.coloredplaybar setProgress:0 animated:NO]; [pcontroller play]; } } else { [detailView.coloredplaybar setProgress:0 animated:NO]; if (pcontroller.playbackState){ [pcontroller play]; } } </code></pre> <p><strong>update playstatus</strong></p> <pre><code>-(void)loginfo { if (pcontroller.playbackState) { float playprocess=(float)pcontroller.currentPlaybackTime/(float)pcontroller.duration; [detailView.coloredplaybar setProgress:playprocess]; if (pcontroller.playbackState==MPMoviePlaybackStateStopped|| pcontroller.playbackState==MPMoviePlaybackStatePaused) { [detailView.playControllButton setImage:playimg forState:UIControlStateNormal]; } else { [detailView.playControllButton setImage:pauseimg forState:UIControlStateNormal]; } } else { [detailView.playControllButton setImage:playimg forState:UIControlStateNormal]; } } - (void)handlePlayback:(NSNotification *)notif { MPMoviePlayerController *theMovie = (MPMoviePlayerController*)[notif object]; if ([theMovie loadState] != MPMovieLoadStateUnknown) { [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerLoadStateDidChangeNotification object:nil]; if ([PlayController getPlayer].loadState == MPMovieLoadStatePlaythroughOK) { if (pcontroller.playbackState &amp;&amp; pcontroller.playbackState == MPMoviePlaybackStatePlaying) { [pcontroller play]; } } } } </code></pre> <p><strong>debug</strong></p> <pre><code>com.apple.coremedia.player.async:EXC_BAD_ACCESS(code = 1,address = 0X4) </code></pre> <p><strong>crash file</strong></p> <pre><code>Incident Identifier: 3CF84469-2C6A-42F8-8DB7-490A8BCB7FCE CrashReporter Key: 3bb7c18d7a7efc7433f20023298207ebb260efd2 Hardware Model: iPhone3,1 Process: HorticulturalJinZhou [1761] Path: /var/mobile/Applications/6A4BA4E5-DDF6-4CF5-A9DC-685C2FE4B799/HorticulturalJinZhou.app/HorticulturalJinZhou Identifier: HorticulturalJinZhou Version: ??? (???) Code Type: ARM (Native) Parent Process: launchd [1] Date/Time: 2013-01-24 12:27:37.314 +0800 OS Version: iPhone OS 5.0.1 (9A405) Report Version: 104 Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Codes: KERN_INVALID_ADDRESS at 0x00000004 Crashed Thread: 10 ![enter image description here][1]![enter image description here][2]![enter image description here][3]![enter image description here][4] ![enter image description here][5]![enter image description here][6] Thread 10 name: com.apple.coremedia.player.async Thread 10 Crashed: 0 WebCore 0x3654b098 WebCore::TimerBase::setNextFireTime(double) + 116 1 WebCore 0x36590862 WebCore::FrameView::layout(bool) + 106 2 WebCore 0x365a8d32 WebCore::FrameView::updateLayoutAndStyleIfNeededRecursive() + 86 3 WebKit 0x34e5e898 -[WebHTMLView(WebInternal) _web_updateLayoutAndStyleIfNeededRecursive] + 36 4 WebKit 0x34e5e79a -[WebHTMLView(WebPrivate) viewWillDraw] + 74 5 CoreFoundation 0x341157fc -[NSObject performSelector:] + 32 6 CoreFoundation 0x3411648a -[NSArray makeObjectsPerformSelector:] + 146 7 CoreFoundation 0x341157fc -[NSObject performSelector:] + 32 8 CoreFoundation 0x3411648a -[NSArray makeObjectsPerformSelector:] + 146 9 CoreFoundation 0x341157fc -[NSObject performSelector:] + 32 10 CoreFoundation 0x3411648a -[NSArray makeObjectsPerformSelector:] + 146 11 CoreFoundation 0x341157fc -[NSObject performSelector:] + 32 12 CoreFoundation 0x3411648a -[NSArray makeObjectsPerformSelector:] + 146 13 WebKit 0x34e5e746 -[WebView(WebPrivate) viewWillDraw] + 86 14 WebCore 0x365a8a6a WebCore::TileCache::prepareToDraw() + 46 15 WebCore 0x36c05270 -[TileLayer layoutSublayers] + 36 16 QuartzCore 0x34ca5f92 CA::Layer::layout_if_needed(CA::Transaction*) + 210 17 QuartzCore 0x34caa114 CA::Context::commit_transaction(CA::Transaction*) + 220 18 QuartzCore 0x34ca9e50 CA::Transaction::commit() + 308 19 QuartzCore 0x34ca9784 CA::Transaction::pop() + 120 20 QuartzCore 0x34ca9704 +[CATransaction commit] + 28 21 MediaToolbox 0x34f30bf0 playerremote_AddToPlayQueue + 356 22 MediaToolbox 0x34f1c540 playerasync_grabAndRunOneCommand + 808 23 MediaToolbox 0x34f1bfd2 fpa_AsyncMovieControlThread + 42 24 CoreMedia 0x320d7bc6 figThreadMain + 146 25 libsystem_c.dylib 0x32f5cc16 _pthread_start + 314 26 libsystem_c.dylib 0x32f5cad0 thread_start + 0 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload