[Android] Result codes from VideoPlayerActivity
Geoffrey Métais
git at videolan.org
Tue May 19 13:41:36 CEST 2015
vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon May 18 16:38:02 2015 +0200| [c66a40bb16d29cabf3b2dcf6371fc4c2e866187d] | committer: Geoffrey Métais
Result codes from VideoPlayerActivity
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=c66a40bb16d29cabf3b2dcf6371fc4c2e866187d
---
.../vlc/gui/video/VideoPlayerActivity.java | 44 ++++++++++++++------
1 file changed, 32 insertions(+), 12 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index f4fa0f8..b3bc9c9 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -43,7 +43,6 @@ import android.media.MediaRouter;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
-import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
@@ -149,6 +148,14 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVideoPlay
public final static String PLAY_EXTRA_FROM_START = "from_start";
public final static String PLAY_EXTRA_OPENED_POSITION = "opened_position";
+ public final static String ACTION_RESULT = "org.videolan.vlc.player.result";
+ public final static String EXTRA_POSITION = "extra_position";
+ public final static String EXTRA_DURATION = "extra_duration";
+ public final static int RESULT_CONNECTION_FAILED = RESULT_FIRST_USER + 1;
+ public final static int RESULT_PLAYBACK_ERROR = RESULT_FIRST_USER + 2;
+ public final static int RESULT_HARDWARE_ACCELERATION_ERROR = RESULT_FIRST_USER + 3;
+ public final static int RESULT_VIDEO_TRACK_LOST = RESULT_FIRST_USER + 4;
+
private SurfaceView mSurfaceView;
private SurfaceView mSubtitlesSurfaceView;
private SurfaceHolder mSurfaceHolder;
@@ -325,7 +332,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVideoPlay
super.onCreate(savedInstanceState);
if (!VLCInstance.testCompatibleCPU(this)) {
- finish();
+ exit(RESULT_CANCELED);
return;
}
@@ -883,11 +890,24 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVideoPlay
mBattery.setText(String.format("%d%%", batteryLevel));
}
else if (action.equalsIgnoreCase(VLCApplication.SLEEP_INTENT)) {
- finish();
+ exit();
}
}
};
+ private void exit(int resultCode){
+ Intent resultIntent = new Intent(ACTION_RESULT);
+ resultIntent.setData(Uri.parse(mLocation));
+ resultIntent.putExtra(EXTRA_POSITION, mLibVLC.getTime());
+ resultIntent.putExtra(EXTRA_DURATION, mLibVLC.getLength());
+ setResult(resultCode, resultIntent);
+ finish();
+ }
+
+ private void exit() {
+ exit(RESULT_OK);
+ }
+
@TargetApi(21)
private void registerV21() {
final IntentFilter intentFilter = new IntentFilter(AudioManager.ACTION_HDMI_AUDIO_PLUG);
@@ -971,7 +991,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVideoPlay
} else if (BuildConfig.tv && mShowing && !mIsLocked) {
hideOverlay(true);
} else
- super.onBackPressed();
+ exit();
}
@Override
@@ -1028,7 +1048,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVideoPlay
return true;
case KeyEvent.KEYCODE_S:
case KeyEvent.KEYCODE_MEDIA_STOP:
- finish();
+ exit();
return true;
case KeyEvent.KEYCODE_DPAD_UP:
case KeyEvent.KEYCODE_DPAD_DOWN:
@@ -1545,7 +1565,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVideoPlay
activity.startPlayback();
break;
case AUDIO_SERVICE_CONNECTION_FAILED:
- activity.finish();
+ activity.exit(RESULT_CONNECTION_FAILED);
break;
case RESET_BACK_LOCK:
activity.mLockBackButton = true;
@@ -1584,7 +1604,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVideoPlay
} else {
/* Exit player when reaching the end */
mEndReached = true;
- finish();
+ exit();
}
}
@@ -1596,7 +1616,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVideoPlay
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
- finish();
+ exit(RESULT_PLAYBACK_ERROR);
}
})
.setTitle(R.string.encountered_error_title)
@@ -1628,13 +1648,13 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVideoPlay
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
- finish();
+ exit(RESULT_HARDWARE_ACCELERATION_ERROR);
}
})
.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
- finish();
+ exit(RESULT_HARDWARE_ACCELERATION_ERROR);
}
})
.setTitle(R.string.hardware_acceleration_error_title)
@@ -1649,7 +1669,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVideoPlay
/* Video track lost, open in audio mode */
Log.i(TAG, "Video track lost, switching to audio");
mSwitchingView = true;
- finish();
+ exit(RESULT_VIDEO_TRACK_LOST);
}
}
@@ -1671,7 +1691,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVideoPlay
}
startActivity(i);
}
- finish();
+ exit();
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
More information about the Android
mailing list