Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added missing calls in order for the example to work. #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 73 additions & 36 deletions example1/src/net/majorkernelpanic/example1/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,50 +1,87 @@
package net.majorkernelpanic.example1;

import net.majorkernelpanic.streaming.SessionBuilder;
import net.majorkernelpanic.streaming.gl.SurfaceView;
import net.majorkernelpanic.streaming.rtsp.RtspServer;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences.Editor;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.WindowManager;

/**
* A straightforward example of how to use the RTSP server included in libstreaming.
*/
public class MainActivity extends Activity {

private final static String TAG = "MainActivity";

private SurfaceView mSurfaceView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

mSurfaceView = (SurfaceView) findViewById(R.id.surface);

// Sets the port of the RTSP server to 1234
Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
editor.putString(RtspServer.KEY_PORT, String.valueOf(1234));
editor.commit();

// Configures the SessionBuilder
SessionBuilder.getInstance()
.setSurfaceView(mSurfaceView)
.setPreviewOrientation(90)
.setContext(getApplicationContext())
.setAudioEncoder(SessionBuilder.AUDIO_NONE)
.setVideoEncoder(SessionBuilder.VIDEO_H264);

// Starts the RTSP server
this.startService(new Intent(this,RtspServer.class));

}

public class MainActivity extends Activity implements Session.Callback {

private final static String TAG = "MainActivity";

private SurfaceView mSurfaceView;

private Session mSession;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

mSurfaceView = (SurfaceView) findViewById(R.id.surface);

// Sets the port of the RTSP server to 8086
Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
editor.putString(RtspServer.KEY_PORT, String.valueOf(8086));
editor.commit();

// Configures the SessionBuilder
mSession = SessionBuilder.getInstance()
.setSurfaceView(mSurfaceView)
.setPreviewOrientation(90)
.setContext(getApplicationContext())
.setCallback(this)
.setAudioEncoder(SessionBuilder.AUDIO_NONE)
.setVideoEncoder(SessionBuilder.VIDEO_H264).build();
mSession.configure();

// Starts the RTSP server
this.startService(new Intent(this,RtspServer.class));

}

@Override
public void onSessionConfigured() {
Log.d(TAG,"Preview configured.");
mSession.start();
}

@Override
public void onBitrateUpdate(long bitrate) {
Log.d(TAG,"Bitrate: "+bitrate);
}

@Override
public void onSessionError(int reason, int streamType, Exception e) {
Log.d(TAG,"onSessionError");

}

@Override
public void onPreviewStarted() {
Log.d(TAG,"onPreviewStarted");

}

@Override
public void onSessionStarted() {
Log.d(TAG,"onSessionStarted");

}

@Override
public void onSessionStopped() {
Log.d(TAG,"onSessionStopped");
}

}