summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian.droege@collabora.co.uk>2012-10-30 09:36:31 (GMT)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>2012-10-30 09:36:31 (GMT)
commitd357a0332a8e80009274ae1b3c9066d78511189e (patch)
tree0197a0cd39b80e6054de50e24aa9ad6340088d92
parentcfcfb180e66c999ac481553e2a16296f58d000cf (diff)
downloadgst-sdk-tutorials-d357a0332a8e80009274ae1b3c9066d78511189e.tar.gz
gst-sdk-tutorials-d357a0332a8e80009274ae1b3c9066d78511189e.tar.xz
Use WakeLock to prevent the screen from blanking during playback
-rwxr-xr-xgst-sdk/tutorials/android-tutorial-5/AndroidManifest.xml1
-rw-r--r--gst-sdk/tutorials/android-tutorial-5/src/com/gst_sdk_tutorials/tutorial_5/Tutorial5.java33
2 files changed, 25 insertions, 9 deletions
diff --git a/gst-sdk/tutorials/android-tutorial-5/AndroidManifest.xml b/gst-sdk/tutorials/android-tutorial-5/AndroidManifest.xml
index bd56b1b..372f319 100755
--- a/gst-sdk/tutorials/android-tutorial-5/AndroidManifest.xml
+++ b/gst-sdk/tutorials/android-tutorial-5/AndroidManifest.xml
@@ -5,6 +5,7 @@
android:versionName="1.0">
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="14"/>
<uses-permission android:name="android.permission.INTERNET"/>
+ <uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-feature android:glEsVersion="0x00020000"/>
<application android:label="@string/app_name"
android:icon="@drawable/gst_sdk_icon">
diff --git a/gst-sdk/tutorials/android-tutorial-5/src/com/gst_sdk_tutorials/tutorial_5/Tutorial5.java b/gst-sdk/tutorials/android-tutorial-5/src/com/gst_sdk_tutorials/tutorial_5/Tutorial5.java
index bd09d45..e3f55fe 100644
--- a/gst-sdk/tutorials/android-tutorial-5/src/com/gst_sdk_tutorials/tutorial_5/Tutorial5.java
+++ b/gst-sdk/tutorials/android-tutorial-5/src/com/gst_sdk_tutorials/tutorial_5/Tutorial5.java
@@ -9,10 +9,12 @@ import com.lamerman.FileDialog;
import com.lamerman.SelectionMode;
import android.app.Activity;
+import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.os.Bundle;
import android.os.Environment;
+import android.os.PowerManager;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
@@ -42,6 +44,8 @@ public class Tutorial5 extends Activity implements SurfaceHolder.Callback, OnSee
private int desired_position;
private Bundle initialization_data;
+
+ private PowerManager.WakeLock wake_lock;
private String mediaUri = "http://docs.gstreamer.com/media/sintel_trailer-480p.ogv";
static private final int PICK_FILE_CODE = 1;
@@ -62,10 +66,16 @@ public class Tutorial5 extends Activity implements SurfaceHolder.Callback, OnSee
setContentView(R.layout.main);
+
+ PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
+ wake_lock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "Android Aurena");
+ wake_lock.setReferenceCounted(false);
+
ImageButton play = (ImageButton) this.findViewById(R.id.button_play);
play.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
is_playing_desired = true;
+ wake_lock.acquire();
nativePlay();
}
});
@@ -74,6 +84,7 @@ public class Tutorial5 extends Activity implements SurfaceHolder.Callback, OnSee
pause.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
is_playing_desired = false;
+ wake_lock.release();
nativePause();
}
});
@@ -81,10 +92,10 @@ public class Tutorial5 extends Activity implements SurfaceHolder.Callback, OnSee
ImageButton select = (ImageButton) this.findViewById(R.id.button_select);
select.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
- Intent i = new Intent(getBaseContext(), FileDialog.class);
- i.putExtra(FileDialog.START_PATH, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).getAbsolutePath());
- i.putExtra(FileDialog.SELECTION_MODE, SelectionMode.MODE_OPEN);
- startActivityForResult(i, PICK_FILE_CODE);
+ Intent i = new Intent(getBaseContext(), FileDialog.class);
+ i.putExtra(FileDialog.START_PATH, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).getAbsolutePath());
+ i.putExtra(FileDialog.SELECTION_MODE, SelectionMode.MODE_OPEN);
+ startActivityForResult(i, PICK_FILE_CODE);
}
});
@@ -113,6 +124,8 @@ public class Tutorial5 extends Activity implements SurfaceHolder.Callback, OnSee
protected void onDestroy() {
nativeFinalize();
+ if (wake_lock.isHeld())
+ wake_lock.release();
super.onDestroy();
}
@@ -132,7 +145,7 @@ public class Tutorial5 extends Activity implements SurfaceHolder.Callback, OnSee
}
/* Called from native code */
- private void onGStreamerInitialized () {
+ private void onGStreamerInitialized () {
if (initialization_data != null) {
is_playing_desired = initialization_data.getBoolean("playing");
int milliseconds = initialization_data.getInt("position");
@@ -149,8 +162,10 @@ public class Tutorial5 extends Activity implements SurfaceHolder.Callback, OnSee
setMediaUri ();
if (is_playing_desired) {
nativePlay();
+ wake_lock.acquire();
} else {
nativePause();
+ wake_lock.release();
}
}
@@ -252,9 +267,9 @@ public class Tutorial5 extends Activity implements SurfaceHolder.Callback, OnSee
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
- if (resultCode == RESULT_OK && requestCode == PICK_FILE_CODE) {
- mediaUri = "file://" + data.getStringExtra(FileDialog.RESULT_PATH);
- setMediaUri();
- }
+ if (resultCode == RESULT_OK && requestCode == PICK_FILE_CODE) {
+ mediaUri = "file://" + data.getStringExtra(FileDialog.RESULT_PATH);
+ setMediaUri();
+ }
}
}