# video Seek time not working

**URL:** <https://forum.developer.roku.com/t/video-seek-time-not-working/1393>\
**Category:** Archived\
**Tags:** roku-developer-program\
**Created:** [March 29, 2012, 11:54am UTC](https://forum.developer.roku.com/t/video-seek-time-not-working/1393 "2012-03-29T11:54:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sunilpawar](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@sunilpawar](https://forum.developer.roku.com/u/sunilpawar)\
**Post date:** [March 29, 2012, 11:54am UTC](https://forum.developer.roku.com/t/video-seek-time-not-working/1393/1 "2012-03-29T11:54:07Z")

</div>

I am playing pre and mid roll ads in my video. i set mid roll ad interval of 5 min (300 seconds)  
after playing the mid-roll ads, instead of showing video from 301 seconds onward, it shows from 0 seconds, i providing the time correctly, but do not know what going one

Explanation  
i increment the variable “video\_playback\_time” and “ad\_frequency\_count” by each second. when “ad\_frequency\_count” i is greaten than equal to ad interval,  
i play the mid-roll ads, then reset the “ad\_frequency\_count” to zero, once ads is complete, i am showing same video by providing “video\_playback\_time” in seconds.  
In “get\_video\_object” function i am converting seek time into milliseconds.  
video.Seek (seek\_time \* 1000) 'providing time in milliseconds

```auto

   ' **************************************************************
    Function get_video_object (content_info, port, seek_time = 0)  
        
        video = CreateObject("roVideoScreen")
        video.SetPositionNotificationPeriod (1)
        video.SetContent (content_info)
        video.SetCGMS (4)
        video.SetMessagePort (port)
        video.Seek (seek_time * 1000) 'providing time in miliseconds
        video.Show ()
        return video
    End Function
    
    
    Function displayVideo(mainMenu as integer,subMenu as integer,isFeatured as integer)
        print "---displayVideo---"
        
        m.adsEnabled = true
        m.ad_interval_sec = 300
            
        if (m.BitRate = Invalid) then
           m.BitRate = 800
        end if
        
        if (m.BitRate.toInt() > 900) then
           m.BitRate = 900
        end if
        
        url = m.url + "?roku_device_id=" + m.device_id
    
        port = CreateObject("roMessagePort")
        videoclip = CreateObject("roAssociativeArray")
    
        if (m.download_url = "" or m.download_url = Invalid) then
            url = m.url + "?roku_device_id=" + m.device_id
            videoclip.StreamFormat = "hls"
            urls = m.Url
            videoclip.StreamUrls = [url]
        else
            url = m.download_url
            videoclip.StreamFormat = "mp4"
            videoclip.StreamUrls = [url]
        end if
    
        videoclip.SDBifUrl = m.bif_sd_url
        videoclip.HDBifUrl = m.bif_hd_url
        videoclip.StreamQualities = ["SD"]
        videoclip.minBandwidth = 10
        videoclip.StreamBitrates = [m.BitRate]
        videoclip.SDBifUrl = m.bif_sd_url
        videoclip.HDBifUrl = m.bif_hd_url
        
        REM Show Preroll
        if m.adsEnabled then
            canvas = show_canvas (port)
            show_ad (port)
            ad_frequency_count = 0
        end if
    
        REM Show video
        video_playback_time = 0
        video = get_video_object (videoclip, port)   
    
        if m.url <> "NOURL" then
            while true
                msg = wait(0, port)
                if type (msg) = "roVideoScreenEvent" then
                    if msg.isScreenClosed () then
                        print "screen closed"
                        exit while
                    else if msg.isStreamStarted () then 
                        print msg.GetMessage ()
                        if m.adsEnabled then
                            canvas.SetLayer (1, {color: "#00000000", CompositionMode: "Source"})
                        end if
                    else if msg.isPlaybackPosition () then 
                        video_playback_time = video_playback_time + 1
                        REM Play midroll every ad_interval_sec
                        
                        if m.adsEnabled and ad_frequency_count >= m.ad_interval_sec then
                            ad_frequency_count = 0
                            video.Close ()
                            print "starting midroll ad"
                            show_ad (port)
                            print "after midroll ad"
                            canvas = show_canvas (port)
                            video = get_video_object (videoclip, port, video_playback_time )
                            video.SetDestinationRect (canvas.GetCanvasRect ())
                        end if
                        if m.adsEnabled
                            ad_frequency_count = ad_frequency_count + 1
                        end if
                    end if 
                end if
            end while
        end if
    End Function

```

---

<div class="post-metadata">

**Author:** ![RokuChris](https://avatars.discourse-cdn.com/v4/letter/r/97f17d/32.png) [@RokuChris](https://forum.developer.roku.com/u/RokuChris)\
**Post date:** [March 29, 2012, 4:20pm UTC](https://forum.developer.roku.com/t/video-seek-time-not-working/1393/2 "2012-03-29T16:20:03Z")

</div>

I don’t remember for sure, but you may have to call Seek() after Show() or even after playback starts.

For mid-rolls, a better approach might be to use the playStart attribute of your content-meta-data instead of Seek().

---

<div class="post-metadata">

**Author:** ![sunilpawar](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@sunilpawar](https://forum.developer.roku.com/u/sunilpawar)\
**Post date:** [April 2, 2012, 10:47am UTC](https://forum.developer.roku.com/t/video-seek-time-not-working/1393/3 "2012-04-02T10:47:31Z")

</div>

Solved this seek time issue for providing time in

```auto
videoclip.PlayStart = seekTime 

```

where seekTime in seconds rather than in mili-seconds

Sunil
