Commit 01f7807f authored by Evan W. Patton's avatar Evan W. Patton Committed by Jeffrey Schiller

Add missing READ_EXTERNAL_STORAGE permission for Player and VideoPlayer

Change-Id: Icebd59c7b7a7e112f42514a3531cb78ef1537c01
parent 9048ac1d
......@@ -6,6 +6,14 @@
package com.google.appinventor.components.runtime;
import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import android.app.Activity;
import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Vibrator;
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.DesignerProperty;
import com.google.appinventor.components.annotations.PropertyCategory;
......@@ -17,20 +25,11 @@ import com.google.appinventor.components.annotations.UsesPermissions;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.common.PropertyTypeConstants;
import com.google.appinventor.components.common.YaVersion;
import com.google.appinventor.components.runtime.errors.IllegalArgumentError;
import com.google.appinventor.components.runtime.errors.PermissionException;
import com.google.appinventor.components.runtime.util.ErrorMessages;
import com.google.appinventor.components.runtime.util.FroyoUtil;
import com.google.appinventor.components.runtime.util.MediaUtil;
import com.google.appinventor.components.runtime.util.SdkLevel;
import android.app.Activity;
import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Vibrator;
import java.io.IOException;
// TODO: This implementation does nothing about releasing the Media
......@@ -175,8 +174,24 @@ public final class Player extends AndroidNonvisibleComponent
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_ASSET,
defaultValue = "")
@SimpleProperty
@UsesPermissions(READ_EXTERNAL_STORAGE)
public void Source(String path) {
sourcePath = (path == null) ? "" : path;
final String tempPath = (path == null) ? "" : path;
if (MediaUtil.isExternalFile(tempPath) && form.isDeniedPermission(READ_EXTERNAL_STORAGE)) {
form.askPermission(READ_EXTERNAL_STORAGE, new PermissionResultHandler() {
@Override
public void HandlePermissionResponse(String permission, boolean granted) {
if (granted) {
Player.this.Source(tempPath);
} else {
form.dispatchPermissionDeniedEvent(Player.this, "Source", permission);
}
}
});
return;
}
sourcePath = tempPath;
// Clear the previous MediaPlayer.
if (playerState == State.PREPARED || playerState == State.PLAYING || playerState == State.PAUSED_BY_USER) {
......
......@@ -6,6 +6,20 @@
package com.google.appinventor.components.runtime;
import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.MediaController;
import android.widget.VideoView;
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.DesignerProperty;
import com.google.appinventor.components.annotations.PropertyCategory;
......@@ -23,20 +37,6 @@ import com.google.appinventor.components.runtime.util.ErrorMessages;
import com.google.appinventor.components.runtime.util.FullScreenVideoUtil;
import com.google.appinventor.components.runtime.util.MediaUtil;
import com.google.appinventor.components.runtime.util.SdkLevel;
import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.MediaController;
import android.widget.VideoView;
import java.io.IOException;
/**
......@@ -193,7 +193,24 @@ public final class VideoPlayer extends AndroidViewComponent implements
description = "The \"path\" to the video. Usually, this will be the "
+ "name of the video file, which should be added in the Designer.",
category = PropertyCategory.BEHAVIOR)
@UsesPermissions(READ_EXTERNAL_STORAGE)
public void Source(String path) {
final String tempPath = (path == null) ? "" : path;
if (MediaUtil.isExternalFile(tempPath)
&& container.$form().isDeniedPermission(READ_EXTERNAL_STORAGE)) {
container.$form().askPermission(READ_EXTERNAL_STORAGE, new PermissionResultHandler() {
@Override
public void HandlePermissionResponse(String permission, boolean granted) {
if (granted) {
VideoPlayer.this.Source(tempPath);
} else {
container.$form().dispatchPermissionDeniedEvent(VideoPlayer.this, "Source", permission);
}
}
});
return;
}
if (inFullScreen) {
container.$form().fullScreenVideoAction(
FullScreenVideoUtil.FULLSCREEN_VIDEO_ACTION_SOURCE, this, path);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment