-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainActivity.java
119 lines (92 loc) · 3.97 KB
/
MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package com.domain.sampleappAKG;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.widget.Toast;
import com.wowza.gocoder.sdk.api.WowzaGoCoder;
import com.wowza.gocoder.sdk.api.errors.WOWZError;
import com.wowza.gocoder.sdk.api.player.WOWZPlayerConfig;
import com.wowza.gocoder.sdk.api.player.WOWZPlayerView;
import com.wowza.gocoder.sdk.api.status.WOWZState;
import com.wowza.gocoder.sdk.api.status.WOWZStatus;
import com.wowza.gocoder.sdk.api.status.WOWZStatusCallback;
public class MainActivity extends AppCompatActivity
implements WOWZStatusCallback {
// The top-level GoCoder API interface
private WowzaGoCoder goCoder;
private WOWZPlayerConfig mStreamPlayerConfig;
private WOWZPlayerView mStreamPlayerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize the GoCoder SDK
goCoder = WowzaGoCoder.init(getApplicationContext(), "KEY-GOES-HERE");
if (goCoder == null) {
// If initialization failed, retrieve the last error and display it
WOWZError goCoderInitError = WowzaGoCoder.getLastError();
Toast.makeText(this,
"GoCoder SDK error: " + goCoderInitError.getErrorDescription(),
Toast.LENGTH_LONG).show();
return;
}
mStreamPlayerView = (WOWZPlayerView) findViewById(R.id.vwStreamPlayer);
mStreamPlayerConfig = new WOWZPlayerConfig();
mStreamPlayerConfig.setIsPlayback(true);
mStreamPlayerConfig.setHostAddress("HOST-ADDRESS");
mStreamPlayerConfig.setApplicationName("live");
mStreamPlayerConfig.setStreamName("STREAM-NAME");
mStreamPlayerConfig.setPortNumber(1935);
mStreamPlayerConfig.setHLSEnabled(true);
mStreamPlayerConfig.setHLSBackupURL("URL");
mStreamPlayerConfig.setAudioEnabled(true);
mStreamPlayerConfig.setVideoEnabled(true);
//WOWZStatusCallback statusCallback = new StatusCallback();
mStreamPlayerView.play(mStreamPlayerConfig, this);
}
@Override
public void onWZError(final WOWZStatus goCoderStatus) {
// If an error is reported by the GoCoder SDK, display a message
// containing the error details using the U/I thread
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this,
"Streaming error: " + goCoderStatus.getLastError().getErrorDescription(),
Toast.LENGTH_LONG).show();
}
});
}
@Override
public void onWZStatus(final WOWZStatus goCoderStatus) {
// A successful status transition has been reported by the GoCoder SDK
final StringBuffer statusMessage = new StringBuffer("Broadcast status: ");
switch (goCoderStatus.getState()) {
case WOWZState.STARTING:
statusMessage.append("Broadcast initialization");
break;
case WOWZState.READY:
statusMessage.append("Ready to begin streaming");
break;
case WOWZState.RUNNING:
statusMessage.append("Streaming is active");
break;
case WOWZState.STOPPING:
statusMessage.append("Broadcast shutting down");
break;
case WOWZState.IDLE:
statusMessage.append("The broadcast is stopped");
break;
default:
return;
}
// Display the status message using the U/I thread
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this, statusMessage, Toast.LENGTH_LONG).show();
}
});
}
}