LogoLogo
v7.0.0
v7.0.0
  • TotalCross Overview
  • TotalCross Javadoc
  • TotalCross Changelog
  • Roadmap
  • Documentation
    • Getting Started
      • First embedded project with TotalCross
    • Components
      • Accordion
      • Aligned Labels
      • Button
      • Check
      • ComboBox
      • Dynamic Scroll
      • Edit
      • Floating Button
      • Gpiod
      • Grid
      • GridContainer
      • Image
      • ImageControl
      • ImageList
      • Label
      • Material Icons
      • Material Window
      • MessageBox
      • Multi Edit
      • Progress Bar
      • Progress Box
      • Radio
      • Radio Group
      • Scroll Container
      • Side Menu
      • Slider
      • Sliding Window
      • Spin List
      • Spinner
      • Switch
      • Tabbed Container
      • Velocimeter
    • APIs
      • API Overview
      • API Rest
      • Asynchronous Task
      • Camera
      • Control
        • Main Window
        • Window
        • Container
      • GPS
      • HTTPS and SSL
      • JSON
      • Maps
        • Maps - Deprecated
        • Static Map
      • Material Design Standards
      • Ninepath
      • Notifications
      • PrinterManager
      • Push Notification Firebase
      • Scanner
      • SOAP
      • Socket
      • SocketServer
      • SQLite Encryption
      • QR Code Generator
      • totalcross.sys
      • Youtube API
    • Creating an Issue
    • Contributing
      • Branch workflow
      • Writing documentation
    • Guides
      • App Architecture
        • Suggested Architecture
        • Why do Design Patterns help with the application's organization?
          • MVC Architecture Pattern
          • Template Pattern
          • Data Persistence: DAO Pattern.
        • Separation of concepts: What is the best way to create UI interfaces?
        • Positioning
          • Manual Positioning
        • Relative Positioning
        • Best practices to improve project maintenance
      • Device Simulator
      • Package your app from scratch
        • TotalCross SDK
        • Environment Variables in IDE
          • Eclipse
          • IntelliJ
        • Deploy your app with a dependecy TC
        • Deploy iOS
          • Using Development certificate to test your apps
      • Understanding TotalCross for Linux ARM
      • Running C++ applications with TotalCross
      • Web Services
    • Miscelaneous
      • Java JDK 8
      • Maven
      • Installing Visual Studio Code
    • FAQ
      • IMEI in Android 10
Powered by GitBook
On this page
  • Overview
  • Source Code
  • Attributes
  • Methods
  • References

Was this helpful?

  1. Documentation
  2. APIs

Youtube API

Overview

Api from youtube allows you to watch a video from youtube on the devices (Android and IOS) using TotalCross.

Source Code

Youtube Example
public class YoutubeDemo extends MainWindow {
    @Override
    public void initUI() {
        Edit.useNativeNumericPad = true;
        Edit startEdit = new Edit();
        startEdit.caption = "start (s)";
        startEdit.setKeyboard(Edit.KBD_NUMERIC);
        startEdit.setText("0");
        Edit endEdit = new Edit();
        endEdit.caption = "end (s)";
        endEdit.setKeyboard(Edit.KBD_NUMERIC);
        startEdit.setText("0");
        Check auto = new Check("autoPlay");
        add(startEdit, CENTER, AFTER + UnitsConverter.toPixels(DP + 16),
                PARENTSIZE + 80, PREFERRED);
        add(endEdit, CENTER, AFTER + UnitsConverter.toPixels(DP + 16),
                PARENTSIZE + 80, PREFERRED);
        add(auto, CENTER, AFTER + UnitsConverter.toPixels(DP + 16),
                PARENTSIZE + 80, PREFERRED);

        Button b = new Button("Open Video");
        add(b, CENTER, AFTER + UnitsConverter.toPixels(DP + 16));

        b.addPressListener((c) -> {
            try {
                int start = startEdit.getText() == null? 0 : (int) Double.parseDouble(startEdit.getText());
                int end = endEdit.getText() == null? -1 : (int) Double.parseDouble(endEdit.getText());
                boolean autoPlay = auto.isChecked();
                new YoutubePlayer()
                        .start(start)
                        .end(end)
                        .autoPlay(autoPlay)
                        .play("o07Ju5snaCw",
                                (state) -> System.out.println("State: " + state));
            } catch (Exception e) {
                new MessageBox("Erro", e.getMessage()).popup();
            }
        });
    }

Attributes

Type

Name

Description

static final int

STATE_UNSTARTED

is a state of when the video has not started yet

static final int

STATE_ENDED

is a state of when the video ended

static final int

STATE_PLAYING

is a state of when the video is still playing

static final int

STATE_PAUSED

is a state of when the video is still paused

static final int

STATE_BUFFERING

is a state of when the video is still loading

static final int

STATE_CUED

is a state of when the video is still cued

static final int

STATE_UNKNOWN

when the player does not know what current state

static final int

ERROR_VIDEO_NOT_FOUND

when the video was not found

static final int

ERROR_UNKNOWN

Unknown error happened

Methods

Type

Name

Description

YoutubePlayer

autoPlay

Sets the video to play automatically when it's loaded.

YoutubePlayer

end

Sets the end point in seconds of the video.

YoutubePlayer

start

Sets the start point in seconds of the video.

void

play(String id)

plays the video that was passed in id

void

play(String id, Callback callback)

plays the video that was passed in the id and has a callback to inform which state of the player

References

Previoustotalcross.sysNextCreating an Issue

Last updated 5 years ago

Was this helpful?

You can view the code shown above in

github