MobileVLCKit thumbnailer issue - ios

I want to create a CVPixelBuffer, since it need a CGImageRef I used [VLCThumbnailer fetchThumbnail] method and crashed with
"Assertion failed: ([thumbnailer dataPointer] == *p_pixels), function
unlock, file
/Users/apple/opensource/vlc-ios/ImportedSources/VLCKit/Sources/VLCMediaThumbnailer.m,
line 74." neither can I find the route"/Users/apple".
Here is the code:
- (void)viewDidLoad {NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:#selector(catchThumbnail) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];}
- (void)catchThumbnail {
if (self.vlcPlayer.hasVideoOut) {
[self.thumbnailer fetchThumbnail];
}}
// VLCMediaThumbnailerDelegate
-(void)mediaThumbnailer:(VLCMediaThumbnailer *)mediaThumbnailer didFinishThumbnail:(CGImageRef)thumbnail {
NSLog(#"-----%#------",thumbnail);
}
worth mentioning: first time it logged :MobileVLCKitPlayer[2736:1068033] -----<CGImage 0x7f803bed56e0>------,but SECOND time crashed
Could someone help me,thanks a lot! :)

I have fixed it, if somebody facing the same issue, remember to set thumbnailer.thumbnail = nil after handling it everytime :)

Related

Is this correct for a NSTimer to get run on the main thread?

Hello I wanted to run a NSTimer on the main thread im not sure if they are run on the main thread by default or I have to do a special implementation ? thanks to anyone who could help
#interface RootViewController : UIViewController {
NSTimer *minutePassed;
}
- (void)adViewDidLoad
{
minutePassed = [NSTimer scheduledTimerWithTimeInterval:60.0 target:self selector:#selector(callMinutedPassed) userInfo:nil repeats:NO];
}
-(void)callMinutePassed
{
NSLog("Minute Passed");
}
Documentation for scheduledTimer(timeInterval:target:selector:userInfo:repeats) states Creates a timer and schedules it on the current run loop in the default mode.. That means in your instance, that it is running on the main thread. I'm assuming when you say -(void)adViewDidLoad you mean -(void)viewDidLoad().

Why isn't my NSTimer calling my method upon expiration?

I am using an NSTimer to call a method which is titled Lose. I had a timer which when it ran out, it called Lose, but I lost everything due to a hard drive error. After trying to code it all again, I can't seem to get the method to be called.
Timer = [NSTimer timerWithTimeInterval:timeMax target:self selector:#selector(Lose) userInfo:nil repeats:NO];
Lose is declared in my .h file, like this:
-(void)Lose;
Also, my method looks like this:
-(void)Lose{
Text.hidden = NO;
scoreLabel.hidden = NO;
Target.hidden = YES;
Targetx.hidden = YES;
if (Score > highScoreNumber) {
highScoreAchieved.hidden = NO;
highScoreNumber = Score;
}
}
The variable timeMax is an int declared in my .h file, like last time.
whenever a target is tapped in my game, timeMax becomes .03 seconds shorter. I do it like this:
timeMax = 5 - (Score * 0.03);
I don't remember it looking different before the massive hardware failure, but why isnt it working?
You have to schedule the timer on a run loop or just use this line instead which schedules it for you:
Timer = [NSTimer scheduledTimerWithTimeInterval:timeMax
target:self
selector:#selector(Lose)
userInfo:nil
repeats:NO];
It's also a good idea to always back up your code...which reminds me.

Creating a boundary for objects

I am fairly new to objective-c and iOS programming in Xcode, and while making my first app I ran into the problem of creating barriers around the edge of the screen which the object cannot pass through. I tried placing objects at the boundary and using CGRectIntersectsRect, but the collision between the boundary and the main object is not registered. Does anyone know how I would go about in doing this?
this is the code that I have used for the object's movement:
const float rate= 0.025;
NSTimer *goLeft;
NSTimer *goRight;
- (IBAction)right {
goRight=[NSTimer scheduledTimerWithTimeInterval:rate
target:self
selector:#selector(goRight)
userInfo:nil
repeats:YES];
if (goRight == nil){
goRight=[NSTimer scheduledTimerWithTimeInterval:rate target:self selector:#selector(goRight) userInfo:nil repeats:YES];
}
}
- (IBAction)left{
goLeft=[NSTimer scheduledTimerWithTimeInterval:rate
target:self
selector:#selector(goLeft)
userInfo:nil
repeats:YES];
if (goLeft == nil){
goLeft=[NSTimer scheduledTimerWithTimeInterval:rate target:self selector:#selector(goLeft) userInfo:nil repeats:YES];
}
}
-(IBAction)stopLeft{
[goLeft invalidate];
goLeft=nil;
}
-(IBAction)stopRight{
[goRight invalidate];
goRight=nil;
}
-(void)goLeft{
_userToken.center =CGPointMake(_userToken.center.x -20, _userToken.center.y);
}
-(void)goRight{
_userToken.center =CGPointMake(_userToken.center.x +20, _userToken.center.y);
}
And for collision with object at left border (userToken and friendly are both UIImageView). However when they collide NSLog is not executed.
-(void)checkForCollision{
if (CGRectIntersectsRect(_userToken.frame, _friendly.frame)){
NSLog(#"Left Intersect");
}
}
You don't say what _userToken.frame and _friendly.frame are set to when you test - it's a good idea to log them while testing so you can manually verify.
An alternative approach, if the valid screen area is a rect, is to check the intersection of the token and the valid area and verify that it is equal to the token frame:
if (CGRectEqualToRect(CGRectIntersection(_userToken.frame, validFrame), _userToken.frame)) { ...
It's important when checking by any method that the frames are in the same coordinate space (that the views have the same superview, or that you convert them to the same common superview) - again, logging will help you to verify this.
Aside:
Trying to recreate the timer if it just failed is unlikely to help. And you should really check for an existing timer and invalidate it before creating a new timer (otherwise you could end up with multiple timers running and no way to stop them).

Call an action at specific intervals in iOS

I am trying to invoke a function that contains ccactioninterval in Cocos3d. I want to call that function at specific time intervals.When I tried NSTimer , i found that it works sometimes and sometimes not.
NSTimer makeTarget=[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:#selector(createTargets) userInfo:nil repeats:YES];
Here createTargets is the function that contains action events. when i run the function straightit works fine for single time. Problem comes when i try to schedule it. I ve tried different methods already explained for related questions . But nothing worked for me. . . .
Here is the code
-(void) addTargets {
NSTimer *makeTarget = [NSTimer scheduledTimerWithTimeInterval:2.0
target:self selector:#selector(createTargets) userInfo:nil repeats:YES];
}
-(void)createTargets {
CC3MeshNode *target = (CC3MeshNode*)[self getNodeNamed: #"obj1"];
int minVal=-5;
int maxVal=5;
float avgVal;
avgVal = maxVal- minVal;
float Value = ((float)arc4random()/ARC4RANDOM_MAX)*avgVal+minVal ;
[target setLocation:cc3v(Value, 5.0, 0.0)];
CCActionInterval *moveTarget = [CC3MoveBy actionWithDuration:7.0 moveBy:cc3v(0.0, -10.0, 0.0)];
CCActionInterval *removeTarget = [CCCallFuncN actionWithTarget:self selector:#selector(removeTarget:)];
[target runAction:[CCSequence actionOne:moveTarget two:removeTarget]];
}
-(void)removeTarget:(CC3MeshNode*)targ {
[self removeChild:targ];
targ=nil;
}
Without much code its hard to tell what you issues is, but here are some things to try apologies if any of this is obvious.
Are you holding onto a reference to the timer?
This might be useful for debugging. If you have a property called makeTargetTimer, then you could do this:
NSTimer * makeTargetTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:#selector(createTargets) userInfo:nil repeats:YES];
self.makeTargetTimer = makeTargetTimer // Save to a property for later use (or just use an iVar)
The only way to stop a re-occurring timer is to invalidate it. Therefore you could check to see if its been invalidated.
BOOL isInvalidated = [self.makeTargetTimer isValid];
Also you might want to do this in your dealloc method anyway:
- (void) dealloc {
[_makeTargetTimer invalidate]; // Stops the timer from firing (Assumes ARC)
}
Are you scrolling when the even should be received?
If you want the timer to be fired while scrolling then you need to use NSRunLoopCommonModes. There is a excellent expiation in this question.
[[NSRunLoop currentRunLoop] addTimer:makeTargetTimer forMode:NSRunLoopCommonModes];
What is your implementation of createTargets like?
Have you put NSLog statements on the body of this method. Are you certain its not being called?

Continuously check for data (method) iOS

Is there any method (like – viewDidLoad) to continuously execute a part of code? I need to be able to check a value on a remote server continuously.
The way you would do this is to set up an NSTimer.
-(void)startCheckingValue
{
mainTimer = [NSTimer timerWithTimeInterval:1.0 target:self selector:#selector(checkValue:) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:mainTimer forMode:NSDefaultRunLoopMode];
}
-(void)checkValue:(NSTimer *)mainTimer
{
//Placeholder Function, this is where you write the code to check your value on the remote server
}
The timerWithTimeInterval function is the one that you are interested in, the main things that you need to pass it, as you see above, are the interval at which it will execute the function whose selector you pass it. The time interval is in seconds, so it is currently set to check every second, which is probably way too fast.
Use an NSTimer to execute the same block of code every x seconds. However, I don't think that's what you want, given that it would put a lot of extra load on the server and you might get banned, so there's probably a better way.
apple's page on NSTimer use
You ned to use NSTimer For this:
in your interface declare a NSTimer object like:
NSTimer *timer;
in your .m viewDidLoad method add the below line.
timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:#selector(timerFireMethod:) userInfo:nil repeats:YES];
In the timerFireMethod method you need to do the server calling and other stuffs.

Resources