Teyuto SDK - Video Module
Overview
The Teyuto.video
module is a core component of the Teyuto SDK, providing comprehensive access to video-related data and functionalities. This module allows developers to control video playback, access video metadata, and respond to various video events within the Teyuto platform.
Key Features
- Video playback control
- Access to video metadata
- Event handling for video interactions
- Video quality and volume management
- Fullscreen control
Properties
The Teyuto.video
object contains various properties that provide information about the current video:
id
: Video's unique identifiertitle
: Video titledescription
: Short description of the videofull_description
: Full description of the videodate
: Upload date of the videoduration
: Duration of the videoprivacy
: Privacy setting of the videosource
: URL of the video sourceimg_preview
: URL of the video preview imagetotal_views
: Total number of viewstotal_likes
: Total number of likestotal_comments
: Total number of commentssource_type
: Type of video source (e.g., "application/x-mpegURL")sprite
: Thumbnail sprite information (if available)popups
: Array of popup information for the video
Methods
onReady(callback)
Executes the provided callback function when the video data is ready.
Teyuto.video.onReady(function(video) {
console.log("Video data loaded:", video);
});
Playback Control
play()
: Starts playing the videopause()
: Pauses the videosetCurrentTime(time)
: Sets the current playback time (in seconds)getCurrentTime()
: Gets the current playback timegetDuration()
: Gets the total duration of the video
Volume Control
setVolume(volume)
: Sets the volume (0 to 1)getVolume()
: Gets the current volumemute()
: Mutes the videounmute()
: Unmutes the video
Fullscreen Control
enterFullscreen()
: Enters fullscreen modeexitFullscreen()
: Exits fullscreen modeisFullscreen()
: Checks if the video is in fullscreen mode
Event Handling
on(eventName, callback)
: Adds an event listener for specific video events
Usage Examples
1. Basic Video Playback Control
Teyuto.video.onReady(function(video) {
console.log("Now playing:", video.title);
// Play the video
video.play();
// Pause after 5 seconds
setTimeout(() => {
video.pause();
console.log("Paused at:", video.getCurrentTime());
}, 5000);
});
2. Custom Video Player Controls
document.getElementById('playBtn').addEventListener('click', () => Teyuto.video.play());
document.getElementById('pauseBtn').addEventListener('click', () => Teyuto.video.pause());
document.getElementById('seekBtn').addEventListener('click', () => {
const seekTime = 30; // Seek to 30 seconds
Teyuto.video.setCurrentTime(seekTime);
});
document.getElementById('volumeSlider').addEventListener('input', (e) => {
Teyuto.video.setVolume(e.target.value / 100);
});
document.getElementById('fullscreenBtn').addEventListener('click', () => {
if (Teyuto.video.isFullscreen()) {
Teyuto.video.exitFullscreen();
} else {
Teyuto.video.enterFullscreen();
}
});
3. Displaying Video Metadata
Teyuto.video.onReady(function(video) {
document.getElementById('videoInfo').innerHTML = `
<h2>${video.title}</h2>
<p>${video.description}</p>
<img src="${video.img_preview}" alt="Video Preview">
<p>Views: ${video.total_views}</p>
<p>Likes: ${video.total_likes}</p>
<p>Comments: ${video.total_comments}</p>
`;
});
4. Handling Video Events
Teyuto.video.onReady(function(video) {
video.on('play', function(data) {
console.log("Video started playing at", data.currentTime);
});
video.on('pause', function(data) {
console.log("Video paused at", data.currentTime);
});
video.on('ended', function() {
console.log("Video playback completed");
// Implement post-video actions here
});
video.on('timeupdate', function(data) {
document.getElementById('progressBar').style.width =
(data.currentTime / video.getDuration() * 100) + '%';
});
});
Best Practices
- Always use the
onReady
method to ensure video data is available before accessing it. - Handle potential errors or unavailable video gracefully.
- Respect video privacy settings when implementing custom functionalities.
- Optimize event listeners, especially for frequently triggered events like 'timeupdate'.
- Provide fallback content or messages for unsupported features or video formats.
- Consider mobile and touch devices when implementing custom video controls.
Conclusion
The Teyuto.video
module offers a powerful set of tools for controlling and interacting with videos on the Teyuto platform. By leveraging this module, developers can create rich, interactive video experiences, customize video players, and implement advanced video-related features in their Teyuto-powered applications.