apivideo_player_android21

Last updated:

0 purchases

apivideo_player_android21 Image
apivideo_player_android21 Images
Add to Cart

Description:

apivideo player android21

api.video Flutter player
api.video is the video infrastructure for product builders. Lightning fast
video APIs for integrating, scaling, and managing on-demand & low latency live streaming features in
your app.
Table of contents #

Table of contents
Project description
Getting started

Installation

Web usage




Documentation

Instantiation

1. The ApiVideoPlayerController
2. The ApiVideoPlayer


Methods
Properties
Events listener

Add a new event listener: Method 1
Add a new event listener: Method 2
Remove an event listener




Dependencies
Sample application
FAQ

Project description #
Easily integrate a video player for videos from api.video in your Flutter application for iOS,
Android and Web.
Getting started #
Installation #
Run the following command at the root of your project.
flutter pub add apivideo_player_android21
copied to clipboard
Web usage #
If you want to use your application as a web app, you need to add the api.video player SDK script in web/index.html from the root of your project.
<!DOCTYPE html>
<html>
<head>
...
<!-- Add the following line inside of the head tag -->
<script src="https://unpkg.com/@api.video/player-sdk" defer></script>
</head>

<body>
...
</body>
</html>
copied to clipboard
Documentation #
Instantiation #
1. The ApiVideoPlayerController #
To use a video player, you must instantiate a new controller.
The ApiVideoPlayerController parameters are:



Parameter
Mandatory
Type
Description




videoOptions
Yes
VideoOptions
Options from the video you want to display inside the current video player


autoplay
No (default false)
bool
Whether you want your video to be automatically played when it's ready or not


onReady
No
VoidCallback
A callback called when the video is ready to be played


onPlay
No
VoidCallback
A callback called when the video is played


onPause
No
VoidCallback
A callback called when the video is paused


onEnd
No
VoidCallback
A callback called when the video has ended


onError
No
Function(Object)
A callback called when an error occured



Once instantiated, you need to initialize the controller by calling its initialize() method.
final ApiVideoPlayerController controller = ApiVideoPlayerController(
videoOptions: VideoOptions(videoId: 'VIDEO_ID'),
);

await controller.initialize();
copied to clipboard
See the sample application below for more details.
2. The ApiVideoPlayer #
A Widget that displays the video and its controls.
The ApiVideoPlayer constructor takes 3 parameters:



Parameter
Mandatory
Type
Description




controller
Yes
ApiVideoPlayerController
The controller that controls a video player


hideControls
No (default false)
bool
Allows you to hide or show the controls of a video player


theme
No (default PlayerTheme)
PlayerTheme
Allows you to customize the video player's colors



final ApiVideoPlayerController controller = ApiVideoPlayerController(
videoOptions: VideoOptions(videoId: 'VIDEO_ID'),
);

await controller.initialize();

Widget build(BuildContext context) {
return ApiVideoPlayer(
controller: controller,
)
}
copied to clipboard
Methods #
Once the ApiVideoPlayerController has been instantiated, you can control the player it has been assigned to with its methods:



Method
Description




play()
Play the video


pause()
Pause the video


seek(Duration offset)
Add/substract the given Duration from the current time


setVolume(double volume)
Change the audio volume to the given value. From 0 to 1 (0 = muted, 1 = 100%)


setIsMuted(bool isMuted)
Mute/unmute the video


setAutoplay(bool autoplay)
Define if the video should start playing as soon as it is loaded


setIsLooping(bool isLooping)
Define if the video should be played in loop


setCurrentTime(Duration currentTime)
Set the current playback time


setVideoOptions(VideoOptions videoOptions)
Set the video options



Example:
final ApiVideoPlayerController controller = ApiVideoPlayerController(
videoOptions: VideoOptions(videoId: 'VIDEO_ID'),
);

await controller.initialize();

controller.play(); // Play the video
copied to clipboard
Properties #
Once the ApiVideoPlayerController has been instantiated, you can access the video player's properties:



Property
Type
Description




isCreated
Future<bool>
Check if the player has been created


isPlaying
Future<bool>
Check whether the video is playing


videoOptions
Future<VideoOptions>
Retrieve the current video options


currentTime
Future<Duration>
Retrieve the current playback time of the video


duration
Future<Duration>
Retrieve the duration of the video


autoplay
Future<bool>
Check whether the video is autoplayed


isMuted
Future<bool>
Check whether the video is muted


isLooping
Future<bool>
Check whether the video is in loop mode


volume
Future<double>
Retrieve the current volume


videoSize
Future<Size?>
Retrieve the current video size



Example:
final ApiVideoPlayerController controller = ApiVideoPlayerController(
videoOptions: VideoOptions(videoId: 'VIDEO_ID'),
);

await controller.initialize();

final bool isMuted = await controller.isMuted;
copied to clipboard
Events listener #
Add a new event listener: Method 1 #
When you instantiate a new ApiVideoPlayerController, you can bind callbacks to some events:
final ApiVideoPlayerController controller = ApiVideoPlayerController(
videoOptions: VideoOptions(videoId: 'VIDEO_ID'),
onPlay: () => print('PLAY'),
onPause: () => print('PAUSE'),
);
copied to clipboard
Add a new event listener: Method 2 #
Once the ApiVideoPlayerController has been instantiated, you can bind callbacks to some events:
final ApiVideoPlayerController controller = ApiVideoPlayerController(
videoOptions: VideoOptions(videoId: 'VIDEO_ID'),
);

await controller.initialize();

final ApiVideoPlayerEventsListener eventsListener =
ApiVideoPlayerEventsListener(
onPlay: () => print('PLAY'),
);

controller.addEventsListener(eventsListener);
copied to clipboard



Event
Type
Description




onReady
VoidCallback
A callback called when the video is ready to be played


onPlay
VoidCallback
A callback called when the video is played


onPause
VoidCallback
A callback called when the video is paused


onEnd
VoidCallback
A callback called when the video has ended


onError
Function(Object)
A callback called when an error occured



Remove an event listener #
To remove an event listener, you need to call the controller's removeEventsListener method.
final ApiVideoPlayerController controller = ApiVideoPlayerController(
videoOptions: VideoOptions(videoId: 'VIDEO_ID'),
);

await controller.initialize();

final ApiVideoPlayerEventsListener eventsListener =
ApiVideoPlayerEventsListener(
onPlay: () => print('PLAY'),
);

controller.removeEventsListener(eventsListener);
copied to clipboard
Dependencies #
We are using external library



Plugin
README




Exoplayer
README.md



Sample application #
import 'package:apivideo_player_android21/apivideo_player_android21.dart';
import 'package:flutter/material.dart';

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

class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);

@override
State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
final ApiVideoPlayerController _controller = ApiVideoPlayerController(
videoOptions: VideoOptions(videoId: 'VIDEO_ID'),
onPlay: () => print('PLAY'),
);
String _duration = 'Get duration';

@override
void initState() {
super.initState();
_controller.initialize();
_controller.addEventsListener(
ApiVideoPlayerEventsListener(
onPause: () => print('PAUSE'),
),
);
}

void _getDuration() async {
final Duration duration = await _controller.duration;
setState(() {
_duration = 'Duration: $duration';
});
}

void _muteVideo() {
_controller.setIsMuted(true);
}

@override
Widget build(BuildContext context) {
return MaterialApp(
home: Builder(builder: (context) {
return Scaffold(
body: Center(
child: Column(
children: <Widget>[
SizedBox(
width: 400.0,
height: 300.0,
child: ApiVideoPlayer(
controller: _controller,
),
),
IconButton(
icon: const Icon(Icons.volume_off),
onPressed: _muteVideo,
),
TextButton(
onPressed: _getDuration,
child: Text(
_duration,
textAlign: TextAlign.center,
),
),
],
),
),
);
}),
);
}
}

copied to clipboard
FAQ #
If you have any questions, ask us in the community. Or
use issues.

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.