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]);
}
Related
I'm trying to use Model I/O as a quicker way to render imported 3d models for my iOS app. I have written a little bit of code importing and displaying a 3d model I have made with a .obj file format. For some reason, when I run my app only a black screen appears.Here is my code:
import UIKit
import ModelIO
import SceneKit
import SceneKit.ModelIO
class ViewController: UIViewController {
var sceneView: SCNView {
return self.view as! SCNView
}
override func viewDidLoad() {
// Do any additional setup after loading the view, typically from a nib.
guard let url = Bundle.main.url(forResource: "Digestive_System", withExtension: "obj") else {
fatalError("Failed to find model")
}
//Load Object
let asset = MDLAsset(url:url)
guard let object = asset.object(at: 0) as? MDLMesh else {
fatalError("failed to get mesh from asset")
}
// Wrap Model I/O object in SceneKit object
let scene = SCNScene()
let node = SCNNode(mdlObject: object)
scene.rootNode.addChildNode(node)
//Display Scene
sceneView.autoenablesDefaultLighting = true
sceneView.allowsCameraControl = true
sceneView.scene = scene
sceneView.backgroundColor = UIColor.black
super.viewDidLoad()
}
side note: my model is located in the main folder of the app.
Thanks for your help guys!
Noa
I have rendered .Obj model using Model I/O as:
Load model from bundle
NSURL *url = [[NSBundle mainBundle] URLForResource:#"modelName" withExtension:#"obj"];
MDLAsset *asset = [[MDLAsset alloc] initWithURL:url];
MDLMesh *meshObject = (MDLMesh *)[asset objectAtIndex:0];
Apply material to model
MDLScatteringFunction *scattering = [MDLScatteringFunction new];
MDLMaterial *mdMaterial = [[MDLMaterial alloc] initWithName:#"material"
scatteringFunction:scattering];
NSURL *baseMaterialURL = [[NSBundle mainBundle]
URLForResource:#"Image_Base_Color" withExtension:#"png"];
MDLMaterialProperty *baseColor = [MDLMaterialProperty new];
[baseColor setType:MDLMaterialPropertyTypeTexture];
[baseColor setSemantic:MDLMaterialSemanticBaseColor];
[baseColour setURLValue:baseMaterialURL];
[material setProperty:baseColor];
for(MDLSubmesh *subMesh in meshObject.submeshes)
{
sub.material = material;
}
Add model to scene
SCNNode *baseModelNode = [SCNNode nodeWithMDLObject:object];
[self.sceneView.scene rootNode] addChildNode:self.baseModelNode];
You can set scale and position as per your requirement.
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
}
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];
}
Hi Im trying to change the tabcontroller flow, so when a user is not loged in just take him to the login view instead the settings one. My controller extends TabBarController and I set the delegate as
self.tabBarController.delegate=self;
My Code is:
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
if (login) {
LoginViewController *loginViewController = [[LoginViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:loginViewController];
[tabBarController presentViewController:loginViewController animated:YES completion:nil];
return NO;
} else {
return YES;
}
I never manage to do the navigation it gives an excetion :
ion 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller <UITabBarController: 0x6a72220>.
I also tried to show the login in as a modal but it only shows a black screen:
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
if (YES) {
LoginViewController *loginViewController = [[LoginViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:loginViewController];
[tabBarController presentModalViewController:navController animated:YES];
return NO;
} else {
return YES;
}
}
Can anybody help Me!!!! please!!!!
Well I manage to fix the black modal screen (still cant d a segue that is not modal).
The problem was that as I am using storyboard I have to load the view from story board as follows.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *navController = [storyboard instantiateViewControllerWithIdentifier:#"login"];
[navController setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentModalViewController:navController animated:YES];
That made the trick :)
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.