เล่นกลับเสียงใน MPMoviePlayerController

ฉันต้องเล่นไฟล์เสียงสองไฟล์ติดกัน ฉันมีไฟล์ทั่วไปที่ระบุว่า: "ฉันชื่อ"

จากนั้นติดตามไฟล์เสียงอื่นซึ่งมีสตริงเสียงอื่น

ตัวอย่างเช่น: พูดว่า a.mp3 มี "ฉันชื่อ" b.mp3 มี "John"

แต่เมื่อฉันตั้งค่า contentURL ของ MPMoviePlayerController โดยจะข้ามเสียงแรกและเล่นเสียงที่สอง

นี่คือรหัสของฉัน:

- (void) playPromptAudio
{[appDelegate.globalPlayer setContentURL:[NSURL 
             URLWithString:@"http://localhost/a.mp3"]];

    [appDelegate.globalPlayer prepareToPlay];
    [appDelegate.globalPlayer play];

    while (appDelegate.globalPlayer.playbackState == MPMoviePlaybackStatePlaying ) {
        // dirty hack, do gracefully
        // do nothing
    }

    [appDelegate.globalPlayer setContentURL:[NSURL URLWithString:@"http://localhost/b.mp3"]];
        [appDelegate.globalPlayer prepareToPlay];
    [appDelegate.globalPlayer play];
}

แต่เมื่อฉันรันโค้ดจะเล่นเฉพาะ "John" เท่านั้น

หลังจากแก้ไขโค้ดแล้ว ฉันเห็นว่าเสียงเริ่มเล่นหลังจากใช้งานฟังก์ชันทั้งหมด ดังนั้นจึงเห็นได้ชัดว่ามีการเล่น "John" เนื่องจากตั้งค่าไว้ล่าสุด แต่มีวิธีป้องกันพฤติกรรมนี้หรือไม่?


person krammer    schedule 26.04.2012    source แหล่งที่มา


คำตอบ (1)


ลองใช้ลิงค์นี้สำหรับการเล่น MPMoviePlayerController

โค้ดด้านล่าง Play MpMoviePlayer พร้อม nodification:

        NSURL *url = [NSURL fileURLWithPath:filePath isDirectory:NO];
        self.moviePlayer = [[[MPMoviePlayerController alloc] initWithContentURL:url]
                    autorelease];
        moviePlayer.shouldAutoplay = NO;
        moviePlayer.view.frame = view_video.bounds;
        moviePlayer.scalingMode= MPMovieScalingModeFill;
        moviePlayer.controlStyle =MPMovieControlStyleNone;
        [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(doneButtonClick:) 
                                                     name:MPMoviePlayerPlaybackDidFinishNotification 
                                                   object:nil];
        [moviePlayer Play]; 

ฟังก์ชั่นด้านล่างเรียกว่า MpMovieplayerController Playbackfinished:

     -(void)doneButtonClick:(NSNotification*)aNotification{
        NSLog(@"MPMoviePlayer is finished..!");
     }

ขอบคุณ....!

person Dinesh    schedule 26.04.2012