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

Post a Comment

Popular posts from this blog

A Flash Light App in Sketchware

Create Music Player app in Sketchware

In Sketchware: How to create a calculator for any simple formula?

Simple car racing android game in Sketchware

Firebase auth in Sketchware for Login Activity