i have an big problem with my situation
my main problem is i need fetch video one by one do some operation on the video name and save it to the file system and again fetch another video do some operation on the video name and save it to the file system through the loop of asset the problem is completion handler prevent me do that because it saving all videos together without i do any editing and changing the name this save all videos i think it is working on background thread please any help to fix this problem i need handle fetch video one by one
this is my code
for asset in arrayOfAssets {
if asset.mediaType == .video {
PHImageManager.default().requestAVAsset(forVideo: asset, options: nil, resultHandler: { (AVAsset, AVAudio, info) in
// i need access to this place so i can fetch the video one by one and working with the AVAsset
})
}else{
let imageOp = PHImageRequestOptions()
PHImageManager.default().requestImage(for: asset, targetSize: CGSize(width:125,height:125), contentMode: .aspectFit, options: imageOp, resultHandler: { (img, info) in
print(img!)
})
}
}
i think this one is related to your query
for Vedios
How Can i Get the List of all Video files from Library in ios sdk
for Images
Get all of the pictures from an iPhone photoLibrary in an array using AssetsLibrary framework?
allVideos = [[NSMutableArray alloc] init];
ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init];
[assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop)
{
if (group)
{
[group setAssetsFilter:[ALAssetsFilter allVideos]];
[group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop)
{
if (asset)
{
dic = [[NSMutableDictionary alloc] init];
ALAssetRepresentation *defaultRepresentation = [asset defaultRepresentation];
NSString *uti = [defaultRepresentation UTI];
NSURL *videoURL = [[asset valueForProperty:ALAssetPropertyURLs] valueForKey:uti];
NSString *title = [NSString stringWithFormat:#"video %d", arc4random()%100];
UIImage *image = [self imageFromVideoURL:videoURL];
[dic setValue:image forKey:#"image"];
[dic setValue:title forKey:#"name"];
[dic setValue:videoURL forKey:#"url"];
[`allVideos` addObject:dic];
}
}];
else
{
}
}
failureBlock:^(NSError *error)
{
NSLog(#"error enumerating AssetLibrary groups %#\n", error);
}];
--------for ALL PHOTOS
NSArray *imageArray;
NSMutableArray *mutableArray;
-(void)getAllPhotosFromCamera
{
imageArray=[[NSArray alloc] init];
mutableArray =[[NSMutableArray alloc]init];
PHImageRequestOptions *requestOptions = [[PHImageRequestOptions alloc] init];
requestOptions.resizeMode = PHImageRequestOptionsResizeModeExact;
requestOptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
requestOptions.synchronous = true;
PHFetchResult *result = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:nil];
NSLog(#"%d",(int)result.count);
PHImageManager *manager = [PHImageManager defaultManager];
NSMutableArray *images = [NSMutableArray arrayWithCapacity:[result count]];
// assets contains PHAsset objects.
__block UIImage *ima;
for (PHAsset *asset in result) {
// Do something with the asset
[manager requestImageForAsset:asset
targetSize:PHImageManagerMaximumSize
contentMode:PHImageContentModeDefault
options:requestOptions
resultHandler:^void(UIImage *image, NSDictionary *info) {
ima = image;
[images addObject:ima];
}];
}
imageArray = [images copy]; // You can direct use NSMutuable Array images
}
Related
I have Qt application, I'm calling UIImagePickerController to get file path for movie the user selected. So I have static functions in Objective-C which call functions from .m file, when user selects movie I can read selected path in another .m function. Question is, how to get this filePath into some Objective-C class where I can call another Qt classes (like Singleton) and pass this result to proper class ?
Objective-C CL_image_call.mm
#include "cl_image_call.h"
#include "cl_image_func.h"
myCLImageClass* CL_image_obj=NULL;
int CL_ImageCCall::CL_objectiveC_Call() {
//Objective C code calling.....
if( CL_image_obj==NULL ) {
//Allocating the new object for the objective C class we created
CL_image_obj=[[myCLImageClass alloc]init];
}
return 1;
}
void CL_ImageCCall::CL_openMedia() {
[CL_image_obj openMedia];
}
CL_image_call.h
#include <QImage>
#include <QString>
#include <QDebug>
#include <stdio.h>
#include "my_singleton.h"
class CL_ImageCCall
{
public:
static int CL_objectiveC_Call();
static void CL_openMedia();
};
CL_image_func.h
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
#import <CoreGraphics/CoreGraphics.h>
#import <UIKit/UIKit.h>
#import <MobileCoreServices/MobileCoreServices.h>
#interface myCLImageClass:NSObject
-(void)openMedia;
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info;
#end
CL_image_func.m
#import "cl_image_func.h"
#interface QIOSViewController : UIViewController
#end
#implementation myCLImageClass
UIImagePickerController *picker=NULL;
UIViewController *viewController=NULL;
NSString *f_path;
-(void)openMedia {
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
viewController = (UIViewController *)([keyWindow rootViewController]);
if (!viewController)
return;
if([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypePhotoLibrary]) {
picker= [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, nil];
[viewController presentViewController:picker animated:YES completion:NULL];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *docDirPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filePath = [docDirPath stringByAppendingPathComponent:#"movie.mov"];
NSLog (#"File Path = %#", filePath);
//filePath is what I need to pass to the rest of my app
[viewController dismissViewControllerAnimated:YES completion:nil];
}
So in CL_image_call.h I have my "my_singleton" where I can reach my whole app, but how to get filePath to this class ?
Best Regards
Marek
Here is the code to export media:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *docDirPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filePath = [docDirPath stringByAppendingPathComponent:#"movie.mov"];
NSLog (#"File Path = %#", filePath);
//filePath is what I need to pass to the rest of my app
NSURL *inputURL = [info objectForKey:UIImagePickerControllerMediaURL];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:inputURL options:nil];
// config the session, maybe some option is not what you need, just config by what you need
AVAssetExportSession *session = [[AVAssetExportSession alloc] initWithAsset:asset
presetName:AVAssetExportPresetMediumQuality];
session.outputURL = [NSURL fileURLWithPath:filePath];
session.outputFileType = AVFileTypeMPEG4;
session.shouldOptimizeForNetworkUse = YES;
[session exportAsynchronouslyWithCompletionHandler:^(void)
{
// do a completion handler
}];
[viewController dismissViewControllerAnimated:YES completion:nil];
}
Then you can visit the output by the filePath, and use when you need.
I have modified code with your suggestion and it does what it should. I'm settings moviePath inside my Qt classes and then I call Objective-C code with this path
NSString *f_path;
//Your objective c code here....
-(void)openMedia:(NSString*)moviePath {
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
f_path=moviePath.copy;
viewController = (UIViewController *)([keyWindow rootViewController]);
if (!viewController)
return;
if([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypePhotoLibrary]) {
picker= [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, nil];
[viewController presentViewController:picker animated:YES completion:NULL];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSURL *inputURL = [info objectForKey:UIImagePickerControllerMediaURL];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:inputURL options:nil];
// config the session, maybe some option is not what you need, just config by what you need
AVAssetExportSession *session = [[AVAssetExportSession alloc] initWithAsset:asset
presetName:AVAssetExportPresetMediumQuality];
session.outputURL = [NSURL fileURLWithPath:f_path];
session.outputFileType = AVFileTypeMPEG4;
session.shouldOptimizeForNetworkUse = YES;
[session exportAsynchronouslyWithCompletionHandler:^(void)
{
// do a completion handler
NSLog (#"export complete = %#", f_path);
}];
[viewController dismissViewControllerAnimated:YES completion:nil];
}
with some trick I can view this movie inside Qt app. One thing that is missing:
I need to know somehow that session has been completed, to refresh file path for MediaPlayer. How can I notify my base class CL_ImageCCall about that. Or actually maybe another Objective-C++ class where I can actually mix Qt and Objective-C ?
Best Regards and thanks for Your help
Marek
is there a way to put UIView by converting it to EAGLView or should i have to add CAlayer ?
whats the best way to do it?
any Example codes related to BuzzCity for Cocos2d would be nice
what i have found till now----
btnAD = [CCMenuItemImage itemFromNormalImage:#"underwater-images-paradox-visual-wallpapers-title-search-196522.jpg" selectedImage:#"underwater-images-paradox-visual-wallpapers-title-search-196522.jpg" target:self selector:#selector(AdbuttonAction)];
btnAD.position=ccp(0, 0);
what i am trying is to display ad on button image...
and call the url for ad on buttonAction
how to display this button on top of my uiview?
documentation of buzzCity ad integration
http://docs.buzzcity.net/wiki/IOS_SDK#Advanced_Integration_using_BuzzCity_iOS_SDK
you can not sandwich UIViews between two cocos nodes. If you want an ad button, display the ad as background of a UIButton, or simply make the ad "touchable" by testing if touch location is within ad's frame.
first i saved my image to documents directory
- (NSString *)saveImage {
NSURL *url = [NSURL URLWithString:#"http://ads.buzzcity.net/show.php?partnerid=8404&browser=app_apple"];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];
//convert image into .png format.
NSData *imageData = UIImagePNGRepresentation(image);
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:#"myImage"];
[imageData writeToFile:fullPath atomically:YES];
NSLog(#"image saved");
return fullPath;
}
then i added that path to **itemFromNormalImage:fullPath**
NSString *fullPath=[self saveImage];
btnAD = [CCMenuItemImage itemFromNormalImage:fullPath selectedImage:fullPath target:self selector:#selector(AdButtonAction)];
NSLog(#"btnAD %#", btnAD);
CCMenu *adMenu = [CCMenu menuWithItems:btnAD, nil];
[self addChild:adMenu];
adMenu.position = ccp(350 ,size.height-50);
finally on button action open the url
-(void)AdButtonAction
{
NSURL *url = [NSURL URLWithString:#"http://click.buzzcity.net/click.php?partnerid=8404&browser=app_apple"];
NSLog(#"url = %#",url);
[[UIApplication sharedApplication] openURL:url];
}
I am trying to load variables into a detail view controller from a NSDictionary in the primary view controller.
I am trying to use the images in the primary view Controller to determine which variable to use in the detail view controller.
My code is like this in the primary View controller;
-(IBAction)pushView:(id) sender{
SomeDetailViewController *detailController = [[SomeDetailViewController alloc] init];
if ((self.imageView.image = [UIImage imageNamed:#"0002.jpg"])) {
NSMutableDictionary *myDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"titleA", #"headerkey2",,nil];
detailController.mapDictionary = mapDictionary;
NSLog(#"%#", [myDictionary objectForKey:#"headerkey2"]);
}
else if((self.imageView.image = [UIImage imageNamed:#"0003.jpg"])) {
NSMutableDictionary *myDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"TitleB", #"headerkey2",,nil];
detailController.myDictionary = myDictionary;
NSLog(#"%#", [myDictionary objectForKey:#"headerkey2"]);
}
[self.navigationController pushViewController:detailController animated:YES];
}
then in my receiving detail view controller my code is;
-(void) viewDidLoad{
[super viewDidLoad];
self.title = [(NSMutableDictionary *)myDictionary objectForKey:#"headerkey2"];
}
Unfortunately this is not working. The same thing shows up for the navigationBar title no matter what.
Can I use a UIImage as a condition?
Any help would be greatly appreciated.
I have used the backlash but doesn't seem to be working in all cases.
Do you use "=" in the if statement for some reason? if not, use "==" instead.
the doc says that [UIImage imageNamed] returns the object associated with specified image, which means it should always return the same object for a same image, so you can use UIImage in condition.
When adding objects to NSArray or NSDictionary, my app only shows a duplicate of the last entry.
I get the data and send it to the observer...
[[NSNotificationCenter defaultCenter] postNotificationName:#"xmlFinishedLoading" object:self userInfo:[NSDictionary dictionaryWithObject:currentEventObject forKey:#"notifKey"]];
This code is ran when observer receives notification...
-(void)populateCurrentEventsTableView:(NSDictionary *)events
{
NSDictionary *info = [events valueForKey:#"userInfo"];
Event *evt = [info valueForKey:#"notifKey"];
if (self.eventDictionary == nil) {
self.eventDictionary = [[NSMutableDictionary alloc]init];
}
[self.eventList addObject:evt];
NSString *key = [NSString stringWithFormat:#"%i",[eventList count] - 1];
[self.eventDictionary setValue:evt forKey:key];
NSLog(#"events description = %#",evt.eventDescription);
[self.tableView reloadData];
}
TableView reloaded with this code...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"ActivitiesList";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
NSUInteger row = [indexPath row];
NSString *rowKey = [NSString stringWithFormat:#"%i",row];
Event *evt = [eventDictionary objectForKey:rowKey];
cell.textLabel.text = evt.eventDescription;
cell.detailTextLabel.text = evt.eventSecondaryDescription;
return cell;
}
The NSLog that displays event description is fine it shows different entries as they come. However if I were to display the entries of eventDictionary, it shows same entry. Any help?
More containing code would be helpful, what you've got looks good to me. What method does this code appear in? Is it possible that self.eventDictionary is being erased each time you come back with a userInfo object to populate it with?
I'm trying to run a QT Movie located in my application bundle. Can't get it to work. Can someone advise?
thanks.
paul
-(IBAction)runInternalMovie:(id)sender
[
NSString *internalPath;
NSURL *internalURL;
QTMovie *internalMovie;
internalPath = [[NSBundle mainBundle] pathForResource: #"bundledMovie"
ofType: #"mp4"];
internalURL = [NSURL fileURLWithPath: internalPath];
internalMovie = [[QTMovie alloc] initWithURL: internalURL byReference: YES];
}
For one thing, there is no initWithURL:byReference: method. There are many ways to create a QTMovie object, none of which have a byReference: parameter and all of which (except for +movie) take an error: output parameter.
Once you're loading the movie, you need to hand it to a QTMovieView for it to display. The easiest way to create such a view is in IB, by dragging it from the Library panel (QuickTime Kit section) to a window in one of your xibs.
Then, either have an outlet in your controller to the movie view and send the movie view a setMovie: message after creating the movie, or bind the movie view's “Movie” property to a property of your controller.
I always use the initWithFile: method of QTMovie:
NSError* error = nil;
NSString* moviePath = [NSBundle pathForResource:#"bundledMovie" ofType:#"mp4" inDirectory:[[NSBundle mainBundle] bundlePath]];
QTMovie* movie = [QTMovie movieWithFile:moviePath error:&error];
if(movie != nil)
{
[movieView setMovie:movie];
}
else
{
NSLog(#"Error loading movie: %#", [error localizedDescription]);
}
Update:
If you want to use NSURL, use the following:
NSError* error = nil;
QTMovie* movie = [QTMovie movieWithURL:[[NSBundle mainBundle] URLForResource:#"bundledMovie" withExtension:#"mp4"] error:&error];
if(movie != nil)
{
[movieView setMovie:movie];
}
else
{
NSLog(#"Error loading movie: %#", [error localizedDescription]);
}