mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-15 03:45:38 +00:00
Use WakeLock to prevent the screen from blanking during playback
This commit is contained in:
parent
cfcfb180e6
commit
d357a0332a
2 changed files with 25 additions and 9 deletions
|
@ -5,6 +5,7 @@
|
||||||
android:versionName="1.0">
|
android:versionName="1.0">
|
||||||
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="14"/>
|
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="14"/>
|
||||||
<uses-permission android:name="android.permission.INTERNET"/>
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
|
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
||||||
<uses-feature android:glEsVersion="0x00020000"/>
|
<uses-feature android:glEsVersion="0x00020000"/>
|
||||||
<application android:label="@string/app_name"
|
<application android:label="@string/app_name"
|
||||||
android:icon="@drawable/gst_sdk_icon">
|
android:icon="@drawable/gst_sdk_icon">
|
||||||
|
|
|
@ -9,10 +9,12 @@ import com.lamerman.FileDialog;
|
||||||
import com.lamerman.SelectionMode;
|
import com.lamerman.SelectionMode;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
import android.os.PowerManager;
|
||||||
import android.view.SurfaceHolder;
|
import android.view.SurfaceHolder;
|
||||||
import android.view.SurfaceView;
|
import android.view.SurfaceView;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -43,6 +45,8 @@ public class Tutorial5 extends Activity implements SurfaceHolder.Callback, OnSee
|
||||||
|
|
||||||
private Bundle initialization_data;
|
private Bundle initialization_data;
|
||||||
|
|
||||||
|
private PowerManager.WakeLock wake_lock;
|
||||||
|
|
||||||
private String mediaUri = "http://docs.gstreamer.com/media/sintel_trailer-480p.ogv";
|
private String mediaUri = "http://docs.gstreamer.com/media/sintel_trailer-480p.ogv";
|
||||||
static private final int PICK_FILE_CODE = 1;
|
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);
|
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);
|
ImageButton play = (ImageButton) this.findViewById(R.id.button_play);
|
||||||
play.setOnClickListener(new OnClickListener() {
|
play.setOnClickListener(new OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
is_playing_desired = true;
|
is_playing_desired = true;
|
||||||
|
wake_lock.acquire();
|
||||||
nativePlay();
|
nativePlay();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -74,6 +84,7 @@ public class Tutorial5 extends Activity implements SurfaceHolder.Callback, OnSee
|
||||||
pause.setOnClickListener(new OnClickListener() {
|
pause.setOnClickListener(new OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
is_playing_desired = false;
|
is_playing_desired = false;
|
||||||
|
wake_lock.release();
|
||||||
nativePause();
|
nativePause();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -81,10 +92,10 @@ public class Tutorial5 extends Activity implements SurfaceHolder.Callback, OnSee
|
||||||
ImageButton select = (ImageButton) this.findViewById(R.id.button_select);
|
ImageButton select = (ImageButton) this.findViewById(R.id.button_select);
|
||||||
select.setOnClickListener(new OnClickListener() {
|
select.setOnClickListener(new OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Intent i = new Intent(getBaseContext(), FileDialog.class);
|
Intent i = new Intent(getBaseContext(), FileDialog.class);
|
||||||
i.putExtra(FileDialog.START_PATH, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).getAbsolutePath());
|
i.putExtra(FileDialog.START_PATH, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).getAbsolutePath());
|
||||||
i.putExtra(FileDialog.SELECTION_MODE, SelectionMode.MODE_OPEN);
|
i.putExtra(FileDialog.SELECTION_MODE, SelectionMode.MODE_OPEN);
|
||||||
startActivityForResult(i, PICK_FILE_CODE);
|
startActivityForResult(i, PICK_FILE_CODE);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -113,6 +124,8 @@ public class Tutorial5 extends Activity implements SurfaceHolder.Callback, OnSee
|
||||||
|
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
nativeFinalize();
|
nativeFinalize();
|
||||||
|
if (wake_lock.isHeld())
|
||||||
|
wake_lock.release();
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,8 +162,10 @@ public class Tutorial5 extends Activity implements SurfaceHolder.Callback, OnSee
|
||||||
setMediaUri ();
|
setMediaUri ();
|
||||||
if (is_playing_desired) {
|
if (is_playing_desired) {
|
||||||
nativePlay();
|
nativePlay();
|
||||||
|
wake_lock.acquire();
|
||||||
} else {
|
} else {
|
||||||
nativePause();
|
nativePause();
|
||||||
|
wake_lock.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,9 +267,9 @@ public class Tutorial5 extends Activity implements SurfaceHolder.Callback, OnSee
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||||
{
|
{
|
||||||
if (resultCode == RESULT_OK && requestCode == PICK_FILE_CODE) {
|
if (resultCode == RESULT_OK && requestCode == PICK_FILE_CODE) {
|
||||||
mediaUri = "file://" + data.getStringExtra(FileDialog.RESULT_PATH);
|
mediaUri = "file://" + data.getStringExtra(FileDialog.RESULT_PATH);
|
||||||
setMediaUri();
|
setMediaUri();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue