Api from youtube allows you to watch a video from youtube on the devices (Android and IOS) using TotalCross.
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();
}
});
}