Tivio Flutter SDK

Initialize Tivio


  • Parameter secret is generated in administration and identifies the application.
  • Parameter language is language of the application.
  • Parameter logLevel sets log level of the sdk.
  • initTivio returns a Tivio instance.
enum TivioLanguages { cs, en, sk, de, pl }
enum TivioLogLevels { verbose, debug, info, warning, error, nothing }

Future<Tivio> initTivio({String secret, TivioLanguages language, TivioLogLevels logLevel});

Example of initialization

import 'package:tivio_sdk/tivio.dart';

class App {
    Tivio _tivio;

    init () async {
        _tivio = await initTivio(secret: 'a18b5f9e-4eb3-4bdb-a69b-660f1cd0d9b9', language: TivioLanguages.cs);
    }
}

Reactive data


TivioDataStream

  • Wrapper of dart Stream
class TivioDataStream<T> {
  Stream<T> get stream;
  close();
}

Widget

class Tivio {
    TivioDataStream<TivioDataWidget> subscribeToWidget({required String widgetId, int count = 10});
}

Channel

class Tivio {
    TivioDataStream<TivioDataPagination<TivioDataChannel>> subscribeToChannelsInWidget({required String widgetId, int count = 10});

    fetchNextChannelsInWidget({required String widgetId, int count = 10});

    TivioDataStream<TivioDataChannel> subscribeToChannel({required String channelId});
}

Section

class Tivio {
    TivioDataStream<TivioDataPagination<TivioDataSection>> subscribeToSectionsInChannel({required String channelId, int count = 10});

    fetchNextSectionsInChannel({required String channelId, int count = 10});

    TivioDataStream<TivioDataSection> subscribeToSection({required String sectionId});
}

Video

class Tivio {
    TivioDataStream<TivioDataPagination<TivioDataVideo>> subscribeToVideosInSection ({required String sectionId, int count = 10});

    fetchNextVideosInSection({required String sectionId, int count = 10});

    TivioDataStream<TivioDataVideo> subscribeToVideo({required String videoId});
}

Recent

class Tivio {
    TivioDataStream<TivioDataPagination<TivioDataVideo>> subscribeToRecentVideosInWidget({required String widgetId, int count = 10});

    TivioDataStream<TivioDataPagination<TivioDataVideo>> subscribeToRecentVideosInChannel({required String channelId, int count = 10});
}
class Tivio {
    Future<TivioDataPagination<TivioDataChannel>> searchChannels({required String query, int limit = 10});

    Future<TivioDataPagination<TivioDataVideo>> searchVideos({required String query, int limit = 10});
}

DTO

Pagination

  • Result of methods that can return a larger amount of data is wrapped in the Pagination object.
  • To get all records iterate until the hasNextPage is true.
  • Called method can have a count parameter to change the number of returned records.
class TivioDataPagination<T> {
  List<T> records;
  bool hasNextPage;
}

Widget

  • A widget holds together multiple channels with some specific configuration.
class TivioDataWidget {
  String id;
  String name;
}

Channel

  • The Channel is a container for multiple sections.
class _ChannelImages {
  String logo;
  String cover;
}

class TivioDataChannel {
  String id;
  String name;
  _ChannelImages images;
}

Section

  • The Section is a container for multiple videos.
class TivioDataSection {
  String id;
  String name;
}

Video

class _Url {
  String hls;
}

class _VideoImages {
  String cover;
}

class _Monetization {
    num price;
    String type;
}

class TivioDataPlaylistItem {
    String name;
    _Url url;
    Duration duration;
}

class TivioDataVideo {
  String id;
  String name;
  Duration duration;
  DateTime created;
  bool isPlaylist;
  List<TivioDataPlaylistItem> playlistItems;
  _Url url;
  _VideoImages images;
  _Monetization monetization;
}

Video player

Declarative api

import 'package:tivio_sdk/tivio.dart';

class App extends StatefulWidget {
  @override
  _AppState createState() => __AppState();
}

class _AppState extends State<App> {
    bool _isTivioInitialized = false;
    Tivio _tivio;

    @override
    void initState() {
        super.initState();
        initializeTivio();
    }

    initializeTivio() async {
        _tivio = await initTivio('a18b5f9e-4eb3-4bdb-a69b-660f1cd0d9b9');

        setState(() {
            _isTivioInitialized = true;
        });
    }

    @override
    Widget build(BuildContext context) {
        return (_isTivioInitialized)
            ? Column(
                children: [
                    TivioPlayer(
                        playerId: 'MainPlayer',
                        tivio: _tivio,
                        source: TivioDataVideo(
                            '4PlQ6BE0oPFfMMjqAjsU',
                            'Episode 1',
                            Duration(milliseconds: 1200080),
                            DateTime(2020),
                            'https://cdn1.tiv.io/video/playlist.m3u8',
                            'https://cdn1.tiv.io/some-image.jpg',
                            false,
                            null,
                            null,
                        ),
                    ),
                ],
            )
            : Text('...');
    }
}

Imperative api

import 'package:tivio_sdk/tivio.dart';

class App extends StatefulWidget {
  @override
  _AppState createState() => __AppState();
}

class _AppState extends State<App> {
    bool _isTivioInitialized = false;
    Tivio _tivio;
    TivioPlayerController _tivioPlayerController;

    @override
    void initState() {
        super.initState();
        initializeTivio();
    }

    initializeTivio() async {
        _tivio = await initTivio('a18b5f9e-4eb3-4bdb-a69b-660f1cd0d9b9');
        _tivioPlayerController = TivioPlayerController();

        setState(() {
            _isTivioInitialized = true;
        });
    }

    @override
    Widget build(BuildContext context) {
        return (_isTivioInitialized)
            ? Column(
            children: [
                TivioPlayer(
                    playerId: 'MainPlayer',
                    tivio: _tivio,
                    controller: _tivioPlayerController,
                ),
                Column(
                    children: [
                        TextButton(
                            onPressed: () {
                                _tivioPlayerController.openAndPlay(
                                  TivioDataVideo(
                                        '4PlQ6BE0oPFfMMjqAjsU',
                                        'Episode 1',
                                        Duration(milliseconds: 1200080),
                                        DateTime(2020),
                                        'https://cdn1.tiv.io/video/playlist.m3u8',
                                        'https://cdn1.tiv.io/some-image.jpg',
                                        false,
                                        null,
                                        null,
                                    ),
                                );
                            },
                            child: Text('Play Episode 1'),
                        ),
                    ],
                )
            ],
        )
            : Text('...');
    }
}

Api

TivioPlayer

class TivioPlayer extends StatefulWidget {
  TivioPlayer({
    required String this.playerId,
    required Tivio this.tivio,
    TivioDataVideo tivioVideoSource,
    TivioPlayerController tivioPlayerController,
    TivioPlayerColors tivioPlayerColors,
    bool startInFullscreen = false,
  });
}

TivioPlayerColors

class TivioPlayerColors {
  final Color progressBarPlayed;
}

TivioPlayerLayout

enum TivioPlayerLayoutTopLeft {
  custom,
}

enum TivioPlayerLayoutTopRight {
  custom,
}

enum TivioPlayerLayoutBottomRight {
  toggleFullscreen,
}

class TivioPlayerLayout {
  final TivioPlayerLayoutTopLeft? topLeft;
  final Widget? topLeftCustomWidget;
  final TivioPlayerLayoutTopRight? topRight;
  final Widget? topRightCustomWidget;
  final TivioPlayerLayoutBottomRight? bottomRight = TivioPlayerLayoutBottomRight.toggleFullscreen;
}

TivioPlayerController

class TivioPlayerController {
    void play ();
    void pause ();
    void openAndPlay (TivioDataVideo source);
    void seekTo (Duration time);
}

Libraries

better_player_ad_controls
better_player_control
better_player_custom_controls
better_player_error
better_player_material_progress_bar
better_player_ui_press_controls
bridge
center_buffering_indicator
dto
enum
logger
message_broker
streams
svg_button
tivio
tivio_languages
tivio_log_levels
tivio_player
tivio_player_colors
tivio_player_controller
tivio_player_input_source
tivio_player_layout
tivio_player_layout
tivio_player_loader
tivio_player_state
tivio_player_wrapper