iOS Question VideoPlayer Position Issue

cooperlegend

Active Member
Licensed User
Longtime User
I am using VideoPlayer in the iPad version of my App, Videoplayer reports back position of the video in 1 second increments (1000,2000 etc)

But when I try to set the Position it will round up or down to the nearest 10 seconds.

Is there a way to make this more accurate (i.e. to the closest second)

The parameter is specified in millseconds, it would nice if I could be more accurate with getting or setting the position of the video playing.
 

cooperlegend

Active Member
Licensed User
Longtime User
Thanks Erel

I don't use the controller anyway, I have implemented my own slider bar to track and set the position of the video, but it just jumps to the nearest 10 seconds.
How do I implement my own that controls the video to smaller increments?
 
Upvote 0

cooperlegend

Active Member
Licensed User
Longtime User
B4X:
Sub slideVideo_ValueChanged(Value As Int)
    vpAnim.Position = vpAnim.Duration * Value / 100
    lblTime.Text = NumberFormat2(vpAnim.Position / 1000, 1, 2, 2, True)
    tmrVideo.Enabled = True
End Sub
 
Upvote 0

cooperlegend

Active Member
Licensed User
Longtime User
B4X:
Video Playing
Received memory warning.
2340
3120
3510
4680
5460
6630
8190
8970
10530
11700
12480
12870
13650
14430
15600
16770
17940
18720
19890
20280
21450
21840
22230
23400
24180
24570
25740
26130
26520
27300
27690
28080
28470
28080
27690
27300
26520
25740
24960
24180
23010
21450
21060
20280
19890
19110
18720
17940
17550
17160
16380
14820
14430
13650
12870
12480
12090
11700
10920
9750
9360
8580
8190
7800
7410
7020
6630
6240
5850

As you can see the issue isn't with the Value passed to ValueChanged, that is correct.
But when you set vpAnim.Position to this value it jumps to the nearest multiple of 10,000 and sets Position to the nearest 10 seconds (rounding up or down)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Interesting discussion about this issue: https://stackoverflow.com/questions/11462843/avplayer-seektotime-does-not-play-at-correct-position

The behavior depends on the video source and encoding.

SeekWithNoTolerance:
B4X:
Sub SeekWithNoTolerance (Position As Int)
    Dim controller As NativeObject = VideoPlayer1
    controller = controller.GetField("controller")
    Dim no As NativeObject = Me
    no.RunMethod("SeekWithNoTolerance::", Array(controller, Position))
End Sub

#if OBJC
- (void)SeekWithNoTolerance:(AVPlayerViewController*)controller :(int)Position {
    int32_t timeScale = controller.player.currentItem.asset.duration.timescale;
    CMTime time = CMTimeMakeWithSeconds(Position / 1000.0, timeScale);
    [controller.player.currentItem seekToTime:time toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero];
}
#End If
 
Upvote 0
Top