I have an image animation with total duration of 2 seconds and in total 6 images. It's a blinking button. I want to play a sound every time that button blink, so in interval of 0.66 seconds by 3 times. I tried do this but the last sound play its a microsecond delay that i dont want..What i can do to play the sound right?
I'm doing this:
-(void)playAnswerAnimSound
{
if(audioActive)
{
if(answerAnimCounter <3)
{
//AudioServicesDisposeSystemSoundID(answerAnimSound);
AudioServicesPlaySystemSound(answerAnimSound);
[answerAnimTimer invalidate];
answerAnimTimer = [NSTimer scheduledTimerWithTimeInterval:0.6666 target:self selector:#selector(playAnswerAnimSound) userInfo:nil repeats:NO];
answerAnimCounter++;
}
else if(answerAnimCounter == 3)
{
answerAnimCounter =0;
[answerAnimTimer invalidate];
}
}
}
The sound duration is 1 second.
Regards
You cannot sync audio by just generating calls to audio services at time intervals, you need to actually render out a .wav or .m4a file with all the audio clips already spaced out in time. Then, playback the generated audio as 1 longer clip and sync the video to the audio. See the linked answer for more details about the implementation.
Related
I want to scroll a video to a specific time.
For example I have an one minute video with a slider and I want to change the playing position.
- (IBAction)itemSlider:(UISlider *)sender withEvent:(UIEvent*)event
{
if ([event.allTouches anyObject].phase == UITouchPhaseEnded)
{
VLCTime *newTime = [VLCTime timeWithNumber:#(sender.value/1000)]; //convert milliseconds to seconds
[mediaplayer.media setLength:newTime]; //tried to set time
}
}
Any ideas?
New time I must set to all mediaplayer player object, not only to media object.
[mediaplayer setTime:newTime];
As always after a lot of searching I back here to get help
my app playing sounds from url, I track the sound playing in uislider by update slider value when start the streamer playing
progressUpdateTimer =
[NSTimer
scheduledTimerWithTimeInterval:0.1
target:self
selector:#selector(updateProgress:)
userInfo:nil
repeats:YES];
- (void)updateProgress:(NSTimer *)updatedTimer
{
[progressView setValue: progress / duration];
}
this is my action for change slider value ( forward / backward the track)
- (IBAction)sliderMoved:(UISlider *)aSlider
{
if (streamer.duration)
{
double newSeekTime = (aSlider.value) * streamer.duration;
[streamer seekToTime:newSeekTime];
}
}
What I want is when the user change the slider the value updates instantly without late of loading .. I mean change the slider value then load the sound
But what happened is by dragging the slider thumb to x position , it backs to its position and then move to x when sound loaded
How can I do that ? any help will be appreciated
in my app i want to add feature . swipe on video take the video to next 2 sec from current playback time. but my player not doing this accurate and exact according to time which i pass to function it jump the current play back time at any where else. i already search a lot and found may be this is due to key-frame of my video i think i need to increase key-frame of video if yes
then (1) what is the best way to increase key-frame of video?
if this issue can solve without increasing key-frame then
(2) how can i do this ?
here is my code
-(void) handleOneFingerSwipeRight
{
if(labelTimer.isValid)
[labelTimer invalidate];
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:#selector(signleTap) object:nil];
[videoPlayer pause];
double d = 0;
d = floor([videoPlayer currentPlaybackTime]);
d = d+2.0;
NSLog(#"current time %f",floor([videoPlayer currentPlaybackTime]));
NSLog(#"new time %f",d);
[videoPlayer setCurrentPlaybackTime:d];
[videoPlayer play];
[self setLable:[NSString stringWithFormat:#"Adaptive Forward %f",d]];
}
I use use AVPlayer to implement a custom player.
Some video playerItem provide the current time and wrong duration. After to seek time use slide to seek time many times. Call the API
When I seek to zero, some video can not be precisely seeked.
[self.player seekToTime:CMTimeMakeWithSeconds(time, NSEC_PER_SEC)
toleranceBefore:CMTimeMake(1, 1)
toleranceAfter:CMTimeMake(1, 1)
completionHandler:^(BOOL finished) {
if (finished) {
IVCLogV(#"seek finish!");
}
else
{
IVCLogV(#"seek interrupted");
}
if (completionHandle) {
completionHandle(finished);
}
}];
I change the codes according the mediaTime.timeScale. Now I discover the video stream have changed the video duration and current time after several play.
Make sure that the Timescale of the media being played matches with your timescale. I can see you have used NSEC_PER_SEC as timescale. You may have to scale your CMTime input to seelTo method.
CMTime timeAccordingToMediaTimescale = CMTimeConvertScale(time, mediaTime.timescale, CMTimeRoundingMethod);
I have an animation of a drinking glass filling up from empty to full, using CAKeyframeAnimation. The animation works perfectly fine.
I need to update a UILabel with the percentage corresponding to the fullness of the glass, i.e. it will read "0%" when the animation begins, and "100%" when it ends.
The keyframe animation runs for 5 seconds. I don't see a good way of updating this label. I can think of two options:
starting another thread and running a polling-type loop that updates the text at the cost of processing power.
break down the animation into 100 parts and use CABasicAnimation to update the text and then proceed with the next bit of glass animation.
Is there a better way to do this?
Thanks in advance
You can use either a NSTImer or dispatch_after() blocks to update the label at some scheduled interval:
// assume an ivar "NSTimer *myTimer" and "int count", initially 0
// fires 20 times, so update is 0.05
myTimer = NSTimer scheduledTimerWithTimeInterval:0.25 target:self selector:#selector(updateLabel:) userInfo:nil repeats:YES
- (void)updateLabel:(NSTimer *)timer
{
++count;
if(count >= 20) {
[timer invalidate];
}
CGFloat percent += 0.05;
myLabel.text = [NSString stringWithFormat:...
}