قم بتشغيل فيديو تم تنزيله في حزمة النظام

StackOverflow https://stackoverflow.com/questions/1377892

  •  21-09-2019
  •  | 
  •  

سؤال

أنا أحاول تنزيل فيديو/صوت على iPhone وتخزينه في حزمة نظام iPhone ، وتشغيل ملف الفيديو/الصوت من الحزمة.

لقد نجحت في تنزيل ملف الفيديو/الصوت باستخدام NSURLConnection. ولدي تخزينها كـ "sample.mov"

لكنني لم أتمكن من تشغيل الفيديو من Bundle. هل لأن الملف لم يكن مسجلاً في الحزمة؟!

هنا هو الرمز:

اكتب إلى ملف عند الانتهاء من التنزيل

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"sample.mov"];

    [VideoData writeToFile:path atomically:YES];
}

ثم أقوم بتشغيل الفيديو من الحزمة

MoviePlayerAppDelegate *appDelegate = (MoviePlayerAppDelegate *)[[UIApplication sharedApplication] delegate];

    // play the movie
    NSBundle *bundle = [NSBundle mainBundle];
    NSString *moviePath = [bundle pathForResource:@"a" ofType:@"mov"];
    NSURL *movURL = [NSURL fileURLWithPath:moviePath];

    [appDelegate initAndPlayMovie:movURL];


-(void)initAndPlayMovie:(NSURL *)movieURL
{
    MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    if (mp)
    {
        // save the movie player object
        self.moviePlayer = mp;
        [mp release];

        // Apply the user specified settings to the movie player object
        [self setMoviePlayerUserSettings];

        // Play the movie!
        [self.moviePlayer play];
    }
}
هل كانت مفيدة؟

المحلول

على حد علمي ، لا يمكنك حفظ الملفات بنجاح إلى مجلد حزمة الموارد.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top