1 package org.freedesktop.gstreamer.tutorials.tutorial_2;
3 import android.app.Activity;
4 import android.os.Bundle;
5 import android.util.Log;
6 import android.view.View;
7 import android.view.View.OnClickListener;
8 import android.widget.ImageButton;
9 import android.widget.TextView;
10 import android.widget.Toast;
12 import org.freedesktop.gstreamer.GStreamer;
14 public class Tutorial2 extends Activity {
15 private native void nativeInit(); // Initialize native code, build pipeline, etc
16 private native void nativeFinalize(); // Destroy pipeline and shutdown native code
17 private native void nativePlay(); // Set pipeline to PLAYING
18 private native void nativePause(); // Set pipeline to PAUSED
19 private static native boolean nativeClassInit(); // Initialize native class: cache Method IDs for callbacks
20 private long native_custom_data; // Native code will use this to keep private data
22 private boolean is_playing_desired; // Whether the user asked to go to PLAYING
24 // Called when the activity is first created.
26 public void onCreate(Bundle savedInstanceState)
28 super.onCreate(savedInstanceState);
30 // Initialize GStreamer and warn if it fails
33 } catch (Exception e) {
34 Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
39 setContentView(R.layout.main);
41 ImageButton play = (ImageButton) this.findViewById(R.id.button_play);
42 play.setOnClickListener(new OnClickListener() {
43 public void onClick(View v) {
44 is_playing_desired = true;
49 ImageButton pause = (ImageButton) this.findViewById(R.id.button_stop);
50 pause.setOnClickListener(new OnClickListener() {
51 public void onClick(View v) {
52 is_playing_desired = false;
57 if (savedInstanceState != null) {
58 is_playing_desired = savedInstanceState.getBoolean("playing");
59 Log.i ("GStreamer", "Activity created. Saved state is playing:" + is_playing_desired);
61 is_playing_desired = false;
62 Log.i ("GStreamer", "Activity created. There is no saved state, playing: false");
65 // Start with disabled buttons, until native code is initialized
66 this.findViewById(R.id.button_play).setEnabled(false);
67 this.findViewById(R.id.button_stop).setEnabled(false);
72 protected void onSaveInstanceState (Bundle outState) {
73 Log.d ("GStreamer", "Saving state, playing:" + is_playing_desired);
74 outState.putBoolean("playing", is_playing_desired);
77 protected void onDestroy() {
82 // Called from native code. This sets the content of the TextView from the UI thread.
83 private void setMessage(final String message) {
84 final TextView tv = (TextView) this.findViewById(R.id.textview_message);
85 runOnUiThread (new Runnable() {
92 // Called from native code. Native code calls this once it has created its pipeline and
93 // the main loop is running, so it is ready to accept commands.
94 private void onGStreamerInitialized () {
95 Log.i ("GStreamer", "Gst initialized. Restoring state, playing:" + is_playing_desired);
96 // Restore previous playing state
97 if (is_playing_desired) {
103 // Re-enable buttons, now that GStreamer is initialized
104 final Activity activity = this;
105 runOnUiThread(new Runnable() {
107 activity.findViewById(R.id.button_play).setEnabled(true);
108 activity.findViewById(R.id.button_stop).setEnabled(true);
114 System.loadLibrary("gstreamer_android");
115 System.loadLibrary("tutorial-2");