Skip to main content

teyuto-flutter-player Github

Installation

Add this to your package's pubspec.yaml file:

dependencies:
teyuto_player: ^1.0.1

Then run the following command:

flutter pub get

Usage

Basic Integration

Import the package in your Dart file:

import 'package:teyuto_player/TeyutoPlayer.dart';

Use the TeyutoPlayer widget in your widget tree:

import 'package:flutter/material.dart';
import 'package:teyuto_player/TeyutoPlayer.dart';

class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
final GlobalKey<TeyutoPlayerState> _teyutoPlayerKey = GlobalKey();
bool playing = false;
double? time;

void handlePlay() {
print("Video is playing");
setState(() {
playing = true;
});
}

void handlePause() {
print("Video is paused");
setState(() {
playing = false;
});
}

void handleTimeUpdate(double _time) {
setState(() {
time = _time;
});
}

void playPlayer() {
final TeyutoPlayerState? playerState = _teyutoPlayerKey.currentState;
if (playerState != null) {
playerState.play();
setState(() {
playing = true;
});
}
}

void pausePlayer() {
final TeyutoPlayerState? playerState = _teyutoPlayerKey.currentState;
if (playerState != null) {
playerState.pause();
setState(() {
playing = false;
});
}
}

@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Teyuto Player SDK Example'),
),
body: Stack(
children: [
Center(
child: TeyutoPlayer(
key: _teyutoPlayerKey,
obj: {
'id': '46760',
'channel': '30Y8zKKY9H3IUaImUidzCqa5852a1cead3fb2b2ef79cf6baf04909',
'options': {'autoplay': 'on'}
},
onPlay: handlePlay,
onPause: handlePause,
onTimeUpdate: (_time) => handleTimeUpdate(_time),
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
playing ? "Playing" : "Pause",
style: const TextStyle(
color: Colors.grey,
),
),
Text(
time?.toString() ?? "",
style: const TextStyle(
color: Colors.grey,
),
),
],
)
],
),
floatingActionButton: FloatingActionButton(
onPressed: () {
handleFloatingActionButtonTap();
},
child: playing ? Icon(Icons.pause_circle) : Icon(Icons.play_arrow),
),
),
);
}

void handleFloatingActionButtonTap() {
if (playing) {
pausePlayer();
} else {
playPlayer();
}
}
}

void main() {
runApp(MyApp());
}

Player Options

Customize the player by passing options in the obj parameter:

TeyutoPlayer(
obj: {
'id': 'VIDEO_ID',
'channel': 'CHANNEL_ID',
'options': {
'autoplay': 'on',
'muted': 'off',
'controls': 'on',
// Add more options as needed
}
},
onPlay: () {
print("Video is playing");
},
onPause: () {
print("Video is paused");
},
onTimeUpdate: (double time) {
print("Current time: $time");
},
onVolumeChange: (double volume) {
print("Current volume: $volume");
},
)

Controlling the Player

Programmatically control the player using the provided methods:

  • play()
  • pause()
  • setCurrentTime(double time)
  • mute()
  • unmute()
  • setVolume(double volume)
  • getCurrentTime()
  • getVolume()

Example:

void playPlayer() {
final TeyutoPlayerState? playerState = _teyutoPlayerKey.currentState;
if (playerState != null) {
playerState.play();
setState(() {
playing = true;
});
}
}

void pausePlayer() {
final TeyutoPlayerState? playerState = _teyutoPlayerKey.currentState;
if (playerState != null) {
playerState.pause();
setState(() {
playing = false;
});
}
}

Event Handling

Handle various player events using callbacks:

TeyutoPlayer(
obj: {
'id': 'VIDEO_ID',
'channel': 'CHANNEL_ID',
'options': {
'autoplay': 'on',
}
},
onPlay: () {
print("Video is playing");
},
onPause: () {
print("Video is paused");
},
onTimeUpdate: (double time) {
print("Current time: $time");
},
onVolumeChange: (double volume) {
print("Current volume: $volume");
},
)

Additional Information

For more information, visit the pub.dev page for Teyuto Player.