I have this sound playing after pressing one button using AudioToolbox.
-(void) onButtonPressSound {
NSString *soundPath = [[NSBundle mainBundle] pathForResource:#"sound" ofType:#"m4a"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath: soundPath], &soundID);
AudioServicesPlaySystemSound (soundID);
}
how can i make it play 2 sounds instead of one, one after the other, after pressing this button?
Thank you,
There are 2 ways of doing this:
first one: for a lazy one like me :)
Take a sound which plays 2 sounds one after other .
Another One:
SystemSoundID receiveMessageSound1;
SystemSoundID receiveMessageSound2;
NSString *sendPath1 = [[NSBundle mainBundle] pathForResource:#"Music1" ofType:#"wav"];
CFURLRef baseURL = (__bridge CFURLRef)[NSURL fileURLWithPath:sendPath];
AudioServicesCreateSystemSoundID(baseURL, &receiveMessageSound1);
AudioServicesPlaySystemSound(receiveMessageSound1);
NSString *sendPath2 = [[NSBundle mainBundle] pathForResource:#"Music2" ofType:#"wav"];
baseURL = (__bridge CFURLRef)[NSURL fileURLWithPath:sendPath2];
AudioServicesCreateSystemSoundID(baseURL, &receiveMessageSound2);
AudioServicesPlaySystemSound(receiveMessageSound2);
Hope this helps.
Related
my app is a AR app to play h.264 video.
We created SKVideoNode by AVPlayer and set the SKVideoNode to SKScene, and then create SCNNode to involve this SKScene.
- Sample Code
AVPlayer *avPlayer = [self getMoviePlayer:path];
SKVideoNode *videoNode = [[SKVideoNode alloc]initWithAVPlayer: avPlayer];
CGSize videoSize = CGSizeMake(100, 50);
videoNode.size = videoSize;
videoNode.position = CGPointMake(50, 50);
videoNode.yScale = -1.0;
SKScene *skScene = [[SKScene alloc] initWithSize:videoSize];
skScene.scaleMode = SKSceneScaleModeAspectFit;
[skScene addChild:videoNode];
SCNNode *planeNode = [[SCNNode alloc] init];
planeNode.geometry = [[SCNPlane alloc] init];
SCNMaterial *material;
material = [[SCNMaterial alloc] init];
material.diffuse.contents = skScene;
planeNode.geometry.firstMaterial = material;
========================
we use this SCNNode to play videos.
it works fine until iOS12.4 but when I test it on iOS13-beta device, it shows black screen while sound is heard.
I had a very similar issue. I also thought it might be an iOS13 bug. But I couldn't reproduce the issue in a test project that was isolating the particular SKVideNode code.
It turned out the root cause of my issue with this problem was in my info.plist file I had PrefersOpenGL set to YES. Changing it to NO (or deleting it) fixed my problem with it not displaying the video in my SKVideoNode iOS 13. It also looks like that change works fine back to iOS 12.4 and 11.4 as well.
I had the same problem. I solved it with replace:
[myViewController.layer addSublayer:playerViewController.view.layer];
by:
[myViewController addSubview:playerViewController.view];
If it can help you.
I'm doing IOS app that recognize 2D image. After recognition it cover the area with read background using this code:
SCNPlane *plane = [SCNPlane planeWithWidth:width height:height];
plane.firstMaterial.diffuse.contents = [UIColor redColor];
Now I want it to play video inside this detected area. I created AVPlayer object using:
NSURL *url = [[NSBundle mainBundle] URLForResource:#"IMG_2099" withExtension:#"MOV"];
AVPlayer *player = [AVPlayer playerWithURL:url];
and added player to material, replacing redColor with:
plane.firstMaterial.diffuse.contents = player;
I guess I need to do something else in order to make AVPlayer play. What should I add to the code (objective c)?
You need to create a SpriteKit scene, add a video node to it, and make it the material of your SceneKit geometry.
I have a very very long text, so instead of using UITextView, I want to truncate the text to small chunks that can fit to a label with width and height 300, 400, and based on number of chunks, I want to create UILabel dynamically and populate them with these chunks.
I have written a method but it seems doesn't return the actual strings that can fit. it returns shorter strings.
am I missing something?
is there anyway I can do this?
- (NSArray *)truncate:(NSString *)text
{
NSMutableArray *textChunks = [[NSMutableArray alloc] init];
NSString *chunk = [[NSString alloc] init];
CTFramesetterRef frameSetter;
UIFont *uiFont = [UIFont systemFontOfSize:17.0f];
CTFontRef ctFont = CTFontCreateWithName((__bridge CFStringRef)uiFont.fontName, uiFont.pointSize, NULL);
NSDictionary *attr = [NSDictionary dictionaryWithObject:(__bridge id)ctFont forKey:(id)kCTFontAttributeName];
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:text attributes:attr];
CFRange fitRange;
while (attrString.length>0) {
frameSetter = CTFramesetterCreateWithAttributedString ((__bridge CFAttributedStringRef) attrString);
CGSize framSize = CTFramesetterSuggestFrameSizeWithConstraints(frameSetter, CFRangeMake(0,0), NULL, CGSizeMake(myLabel.frame.size.width, myLabel.frame.size.height), &fitRange);
NSLog(#"height: %f", framSize.height);
CFRelease(frameSetter);
chunk = [[attrString attributedSubstringFromRange:NSMakeRange(0, fitRange.length)] string];
[textChunks addObject:chunk];
[attrString setAttributedString: [attrString attributedSubstringFromRange:NSMakeRange(fitRange.length, attrString.string.length-fitRange.length)]];
}
return textChunks;
}
Yes, you need to add a paragraph style in order to get the width/height measure to work properly. See giving-framesetter-the-correct-line-spacing-adjustment. Note how CTFontGetLeading() is used to get the font leading and then this property is set vai CFAttributedStringSetAttributes().
I want to draw a route using google api please suggest me is there any google api is available for drawing route between 2 latitude and Longitude.
NSString * urlString = nil;
urlString = [NSString stringWithFormat: #"http://maps.google.com/maps?saddr=%f,%f&daddr=%#",12.58, 77.35, [NSString stringWithFormat:#"%#,%#,%#",[detailInfoDict valueForKey:#"address"],[detailInfoDict valueForKey:#"city"],[detailInfoDict valueForKey:#"state"]]];
urlString = [urlString stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: urlString]]
You can do using this way as well.
Step 1:
Add this Frameworks
Step 2: Imports these files into your View Controllers .h file
Step 3: Provide 2 Location's latitude and longitude in ViewControllers' .m file
OutPut:You will get output like this
I need to change the images/colors (whichever is easier) of buttons in a view different from the one the button is located. Any ideas? This is for iOS and I have been trying for days to get this to work. Thanks!
I don't know if this is the proper way to do this (kinda depends on the context), but you could you us user defaults:
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *fooButtonColor = #"red";
[prefs setObject:fooButtonColor forKey:#"fooButtonColor"];
You would put this code in the .m file of the class where you want to "set" the color. In
Then in the other view, get the color from the defaults and check e.g. by doing a string comparison:
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:fooButtonColor forKey:#"fooButtonColor"];
NSString *fooButtonColor = [prefs objectForkey:#"fooButtonColor"];
if ([fooButtonColor isEqualtoString #"red"]) {
foobutton.backgroundColor = [UIColor redColor];
}
Probably more efficient would be to use rgba values. Check out this question: Saving UIColor to and loading from NSUserDefaults
Good luck