VideoView in Sketchware

To add a VideoView to play videos picked from Sdcard follow following steps in Sketchware.

1. Create a new project in Sketchware.

2. In VIEW area add a Button button1 and a LinearLayout linear2.

3. Create a String List list, and a String variable str.

4. Add a FilePicker component fp with mime type video/*.

5. Create a more block extra.

6. In the more block extra, use an add source directly block and put codes to declare a VideoView vidview and an MediaController mediaControls.
}
VideoView vidview;
MediaController mediaControls;
{

7. In onCreate event, use add source directly blocks and put following codes:
i. Define the VideoView vidview, set it's LayoutParams, and add it to the linear 2.
vidview = new VideoView(this);
vidview.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
linear2.addView(vidview);

ii. Define the MediaController, anchor it to the VideoView, and set it as the MediaController of the VideoView.

mediaControls = new MediaController(this); mediaControls.setAnchorView(vidview); vidview.setMediaController(mediaControls);

iii. Set OnCompletionListener and OnErrorListener for the VideoView.
vidview.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
} });

vidview.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
showMessage("Oops An Error Occured While Playing Video!!");
return false; } });

8. In button1 onClick event use the block FilePicker pick files.

9. In the event FilePicker onFilesPicked, get file path of video picked to String str and set it as the Uri of the vidview.
Following code is used in the add source directly block.
vidview.setVideoURI(Uri.parse(str));
vidview.start();

10. Save and run the project. You can click the Button to pick any video. The picked video plays in VideoView.

* We can also set OnPreparedListener event on VideoView, and play the video when it is ready to play.
vidview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
vidview.start();
} });
In this case we need not use vidview.start(); in FilePicker onFilesPicked event.

Comments

  1. can i pdf book View in Sketchware >> pdf to apk with sketchware ??

    ReplyDelete
    Replies
    1. convert the PDF to E PUB or to HTML, if you want to do it in sketchware, but you can design a PDF reader. if you want to create a PDF book, go to App maker App, you cam make the PDF APK and publish to google play.

      here the link for App Maker App:

      https://play.google.com/store/apps/details?id=com.appmaker.appmaker

      Delete
  2. device = android.os.Build.DEVICE;
    model = android.os.Build.MODEL;
    product = android.os.Build.PRODUCT;
    manufacturer = android.os.Build.MANUFACTURER;
    brand = android.os.Build.BRAND;
    api_level = android.os.Build.VERSION.SDK;
    board = android.os.Build.BOARD;
    boot = android.os.Build.BOOTLOADER;
    display = android.os.Build.DISPLAY;
    fingerprint = android.os.Build.FINGERPRINT;
    hardware = android.os.Build.HARDWARE;
    host = android.os.Build.HOST;
    id = android.os.Build.ID;

    ReplyDelete
  3. I not have any developer account please help me to publish my first app in play store.

    ReplyDelete
  4. Pls tell me Loop options adding!

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. nima uchun shu kodlarni kucirip add dirctlyga tashlasam javaga xato chiqaradi javobini @First_blogger ga yozing

    ReplyDelete
  7. Kenapa finish activity tdk berfungsi,selalu kembali ke halaman sebelumnya??

    ReplyDelete
  8. how can I fitch video from firebase storage in sketchware ?

    ReplyDelete
    Replies
    1. Just you create a variable.... say like he had done it as file...
      The file must contain firebase video URL....
      Just set up that and you will be done....
      Just leave a thanks message if it does help you

      Delete
  9. Please, can you write on how to save a video in app without going to the sdcard to pick a video

    ReplyDelete
  10. How about customizing the media controller to my own custom view?

    ReplyDelete
  11. What about LOOP, REPEAT, it's possible to add to the code?

    ReplyDelete
  12. vidview.setVideoURI(Uri.parse(str));
    vidview.start();

    ReplyDelete
  13. Can we open Camera on linear1 with our options like record button speed setting icon to add filter

    ReplyDelete
  14. Please How Can I implement Subtitles in video view in sketchware?

    ReplyDelete
  15. Скиньте мне готовый ваш пример (формат spk ) фоновое видео в приложении на почту мне, а я в долгу не останусь, моя почта:
    wmclicx@gmail.com

    ReplyDelete
  16. Please do you know how to implement subtitles in video player using Sketchware?

    ReplyDelete

Post a Comment

Popular posts from this blog

Simple car racing android game in Sketchware

Creating a Drawing View in Sketchware

Enable Fullscreen for Youtube videos in WebView

How to enable upload from webview in Sketchware?

List of Calendar Format symbols valid in Sketchware