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];
Related
Sorry for my poor english.
In my work, We made a app which show a high resolution image into a UIScrollVIew. Besides, the user can play a MP3 that animate the position and zoom of UIScrollView from one second with a specific duration showing the detail of image that MP3 is talking about. Currently, the audio play from second 0 to the end sequently. User can´t interactuate with UIScrollView when the MP3 is playing
Now we want that the user can change the current time when is playing, I´m not sure how calculate the position when the user select a second placed in the midst of one animation.
Example:
Second 1: Duration 4; Second 8: Duration 2; Second 20 Duration 10; Second 31 Duration 3;
If the user select the second 24, we would want animate during 6 seconds, but keeping in mind the original position that UIScrollView should have since second 20 to 24 from original animation.
We are using uiview animation (animateWithDuration) with zoomToRect (animated:NO) method from UIScrollView
I´m not sure how calculate those intermediate values.
Thanks.
I do not know, whether I really get you right or wrong. But you can set the animations progress to a progress value that is in relation to the start point and the total duration of the animation. I. e. in your case
float animationStartPoint = 20.0; // Start of the animation
float duration = 10.0; // Its duration
float partialStartPoint = 24.0; // user selected start point
NSAnimation *animation = …;
…
animation.currentProgress = (partialStartPoint-animationStartPoint)/duration;
[animation startAnimation];
I have an instance of AVAudioPlayer that plays a local audio file from disk. The playback progress is reflected with a UIProgressView. I'm trying to replace that with a UISlider. To accomplish the task, the slider will:
move in response to timer event to indicate the current playback position
respond to manual touch to allow for video scrubbing
I'm not sure how to make the UISlider smart enough to know that when human touch began, it should stop responding to timer events, and when the touch is released, it should resume the audio player at a new position and start updating with timer events again.
Which "Send event" outlets in storyboard would I use to create the behavior
above?
Currently I have a generic "value changed" callback.
- (IBAction)sliderChanged:(id)sender {
if(self.backgroundMusicPlayer == nil)
{
NSError* error = nil;
NSData* data = [self.audioFile data];
self.backgroundMusicPlayer = [[AVAudioPlayer alloc]initWithData:data error:&error];
[self.backgroundMusicPlayer prepareToPlay];
}
self.backgroundMusicPlayer.currentTime = self.slider.value;
[self.backgroundMusicPlayer play];
}
What you have is right. To make your code respond to the user adjusting the slider, use the Value Changed event. If you want to be notified that the slider has been touched, use the Touch Down event, or add a gesture recognizer to the slider.
I would keep things simple and just check the isTracking property of UISlider which it inherits from UIControl.
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 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.
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);