2017-08-01 137 views
0

我在視頻源的地圖框中添加了一個圖層。下面是腳本:如何在Mapbox中獲取視頻的當前時間?

map.addSource("storm-source", { 
type: "video", 
urls: [ 
"C:/flood.mp4" // path to our video 
], 
coordinates: [ 
[ -79.1680785004, 34.7195831793 ], 
[ -78.8680220490, 34.7195831793 ], 
[ -78.8680220490, 34.4762734894 ], 
[ -79.1680785004, 34.4762734894 ] 
] // the coordinates to which your data is clipped: 
}); 
// add this layer to the map 
map.addLayer({ 
    "backgroung": 'transparent', 
    "type": 'raster', 
    "id": "storm-layer", 
    "source": "storm-source", 
    paint: { 
     "raster-opacity": 1 
    } 
}, 
'hillshade_shadow_faint'); // "after" our lowest hillshade layer 

現在,當視頻flood.mp4的播放位置發生了變化,我想顯示的視頻在幾秒鐘內的當前位置。 Mapbox的腳本是什麼?我知道兩條語句var mySource = map.getSource("storm-source");mySource.getVideo().currentTime可以給出特定時刻的當前視頻時間,但只要視頻正在運行,我想要始終/連續顯示當前時間。

回答

0

可以使用timeupdate事件的視頻元素觸發:

The timeupdate event is fired when the time indicated by the currentTime attribute has been updated.

參考:https://developer.mozilla.org/en-US/docs/Web/Events/timeupdate

例子:

var mySource = map.getSource("storm-source"); 

mySource.addEventListener('timeupdate', function (e) { 
    console.log(e.target.currentTime); 
}); 

更多的媒體活動在這裏:https://developer.mozilla.org/en/docs/Web/Guide/Events/Media_events

+0

謝謝。其實。我有一個「開始」按鈕,當我點擊按鈕時,視頻應該播放。但是,我試過並顯示錯誤:index.html:188 Uncaught TypeError:mySource.addEventListener不是HTMLButtonElement中的函數 。 (index.html:188) – Kayes

+0

此外,我刪除了「開始」按鈕,並嘗試但得到相同的錯誤:mySource.addEventListener不是一個函數。 – Kayes

+0

沒有看到你的用例在轉載。我只是在這裏猜測 – iH8

相關問題