0

私は safekeep という名前のアプリを 1 つ開発しています。coredata を使用してビデオをデータに変換してインポートする必要があります。

if ([[info objectForKey:UIImagePickerControllerMediaType] isEqualToString:@"public.movie"]) 
{
     NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
     NSLog(@"Q: video path: %@",[videoURL description]);

     self.videoData=[NSData dataWithContentsOfURL:videoURL];
     if(self.videoData)
      {
        NSLog(@"data is present");
        NSManagedObjectContext *context = [appDelegate managedObjectContext];
        NSManagedObject *imagetblObj= [NSEntityDescription insertNewObjectForEntityForName:@"VideoData" inManagedObjectContext:context];
        [imagetblObj setValue:self.videoData forKey:@"videodata"];
        [imagetblObj setValue:str forKey:@"date"];
        NSError *err;
        if (![context save:&err]) 
         {
            NSLog(@"Couldn't save history item into coredata");
         }

        NSLog(@"data saved");
        [self videodatafromdb];
    }
}

-(void)videodatafromdb
{
    NSManagedObjectContext *context = [(AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"VideoData" inManagedObjectContext:context];
    [request setEntity:entity];
NSError *error;
NSArray *recordsData=[context executeFetchRequest:request error:&error];
self.videoarray=[[recordsData reverseObjectEnumerator]allObjects];
NSLog(@"Array count is %d",[self.videoarray count]);
if ([self.videoarray count]>0) 
{
  [self createScrollViewvideo];
}
}

-(void)createScrollViewvideo
{
    NSLog(@"in create scrollviewvideo");
    //add views to scrolview
    int x=5;
    int y=17;
    for(int i=0;i<[videoarray count];i++)
    {
        UIImage *imag=[[UIImage alloc] init];
        UIView *videoview=[[UIView alloc] initWithFrame:CGRectMake(x, y, 100, 100)];
        videoview.tag=i;

        UIButton *userButton=[[UIButton alloc]initWithFrame:CGRectMake(1, 1, 100,100)];
        [userButton addTarget:self action:@selector(userVideoClicked:) forControlEvents:UIControlEventTouchUpInside];
        userButton.tag=i;
        imag=[UIImage imageWithData:videoData];

        [userButton setBackgroundImage:imag forState:UIControlStateNormal];

        [videoview addSubview:userButton];
        [self.scrollview addSubview:videoview];


        [userButton release];
        [videoview release];

        x+=104;
        if ((i+1)%3==0) 
        {
            y+=110;
            x=5;
        }

    }
    NSLog(@"10000in create scrollview");
    if (y+110>self.scrollview.frame.size.height) 
    {
        self.scrollview.contentSize=CGSizeMake(320, y+110);
    }
    else
    {
        self.scrollview.contentSize=CGSizeMake(320, self.scrollview.frame.size.height+60);
    }
 }
}

-(IBAction)userVideoClicked:(id)sender { NSLog(@"クリックされたビデオ");

UIButton *button=(UIButton*)sender;

VideoData *videoobj=(VideoData *)[self.videoarray  objectAtIndex:[button tag]];

NSLog(@"video data is %@",videoobj);

VidoesVIewController *videoviewcontroller=[[VidoesVIewController alloc] initWithNibName:@"VidoesVIewController" bundle:nil];

videoviewcontroller.videodata=[videoobj valueForKey:@"videodata"];

[self.navigationController pushViewController:videoviewcontroller animated:YES];

[videoviewcontroller release];

}

動画がスクロール ビューに表示されません。ただし、動画ファイルをクリックするとナビゲートされます。画像がボタンに設定されている場合、画像がビューに表示されます。よろしくお願いします。

4

1 に答える 1

0

私の答えを見てください:

Core Data の外部バイナリ ストレージに使用されるファイルにアクセスできますか?

私は「創造的な」解決策を思いつきました (ベスト プラクティスが誰かの推測であるかどうかに関係なく)、Core Data を使用してファイルを管理しながら、パスで REAL ファイルにアクセスすることができます。

バイナリ フィールドで [外部ストレージを許可] オプションを使用すると、コア データがファイルへの参照を管理できるようになり、かなりの量の忙しい作業を抽象化できます。

于 2012-11-21T17:17:53.097 に答える