Created
July 12, 2017 01:22
-
-
Save fitraditya/b2283095b03c4f0d6dcd2055336ea5a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:id="@+id/activity_example_rtmp" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".defaultexample.ExampleRtmpActivity" | |
> | |
<SurfaceView | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:id="@+id/surfaceView" | |
/> | |
<EditText | |
android:hint="@string/hint_rtmp" | |
android:textColor="@color/appColor" | |
android:textColorHint="@color/appColor" | |
android:inputType="textUri" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:gravity="center" | |
android:layout_margin="20dp" | |
android:id="@+id/et_rtmp_url" | |
/> | |
<Button | |
android:text="@string/start_button" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_alignParentBottom="true" | |
android:layout_centerHorizontal="true" | |
android:layout_margin="20dp" | |
android:id="@+id/b_start_stop" | |
/> | |
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
<uses-permission android:name="android.permission.INTERNET" /> | |
<uses-permission android:name="android.permission.RECORD_AUDIO" /> | |
<uses-permission android:name="android.permission.CAMERA" /> | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
allprojects { | |
repositories { | |
maven { url 'https://jitpack.io' } | |
} | |
} | |
dependencies { | |
compile 'com.github.fitraditya:rtmp-rtsp-stream-client-java:4a0fbf39da' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.rtmpapp; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.SurfaceView; | |
import android.view.View; | |
import android.view.WindowManager; | |
import android.widget.Button; | |
import android.widget.EditText; | |
import android.widget.Toast; | |
import com.pedro.builder.rtmp.RtmpBuilder; | |
import com.pedro.rtmpstreamer.R; | |
import net.ossrs.rtmp.ConnectCheckerRtmp; | |
public class ExampleRtmpActivity extends AppCompatActivity implements ConnectCheckerRtmp, View.OnClickListener { | |
private RtmpBuilder rtmpBuilder; | |
private Button button; | |
private EditText etUrl; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); | |
setContentView(R.layout.activity_example_rtmp); | |
SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surfaceView); | |
button = (Button) findViewById(R.id.b_start_stop); | |
button.setOnClickListener(this); | |
etUrl = (EditText) findViewById(R.id.et_rtmp_url); | |
rtmpBuilder = new RtmpBuilder(surfaceView, this); | |
} | |
@Override | |
public void onConnectionSuccessRtmp() { | |
runOnUiThread(new Runnable() { | |
@Override | |
public void run() { | |
Toast.makeText(ExampleRtmpActivity.this, "Connection success", Toast.LENGTH_SHORT).show(); | |
} | |
}); | |
} | |
@Override | |
public void onConnectionFailedRtmp() { | |
runOnUiThread(new Runnable() { | |
@Override | |
public void run() { | |
Toast.makeText(ExampleRtmpActivity.this, "Connection failed", Toast.LENGTH_SHORT).show(); | |
rtmpBuilder.stopStream(); | |
button.setText(getResources().getString(R.string.start_button)); | |
} | |
}); | |
} | |
@Override | |
public void onDisconnectRtmp() { | |
runOnUiThread(new Runnable() { | |
@Override | |
public void run() { | |
Toast.makeText(ExampleRtmpActivity.this, "Disconnected", Toast.LENGTH_SHORT).show(); | |
} | |
}); | |
} | |
@Override | |
public void onAuthErrorRtmp() { | |
runOnUiThread(new Runnable() { | |
@Override | |
public void run() { | |
Toast.makeText(ExampleRtmpActivity.this, "Auth error", Toast.LENGTH_SHORT).show(); | |
} | |
}); | |
} | |
@Override | |
public void onAuthSuccessRtmp() { | |
runOnUiThread(new Runnable() { | |
@Override | |
public void run() { | |
Toast.makeText(ExampleRtmpActivity.this, "Auth success", Toast.LENGTH_SHORT).show(); | |
} | |
}); | |
} | |
@Override | |
public void onClick(View view) { | |
if (!rtmpBuilder.isStreaming()) { | |
if (rtmpBuilder.prepareAudio() && rtmpBuilder.prepareVideo()) { | |
button.setText(getResources().getString(R.string.stop_button)); | |
rtmpBuilder.startStream(etUrl.getText().toString()); | |
} else { | |
Toast.makeText(this, "Error preparing stream, This device cant do it", Toast.LENGTH_SHORT) | |
.show(); | |
} | |
} else { | |
button.setText(getResources().getString(R.string.start_button)); | |
rtmpBuilder.stopStream(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment