初步避開閃退問題
This commit is contained in:
@@ -348,8 +348,8 @@ void gst_native_set_uri(JNIEnv *env, jobject thiz, jstring uri) {
|
||||
gst_element_set_state(data->pipeline, GST_STATE_READY);
|
||||
g_object_set(data->pipeline, "uri", char_uri, NULL);
|
||||
(*env)->ReleaseStringUTFChars(env, uri, char_uri);
|
||||
data->is_live |=
|
||||
(gst_element_set_state(data->pipeline, data->target_state) == GST_STATE_CHANGE_NO_PREROLL);
|
||||
g_object_set(data->pipeline, "latency", 250, NULL);
|
||||
data->is_live = (gst_element_set_state(data->pipeline, data->target_state) == GST_STATE_CHANGE_NO_PREROLL);
|
||||
}
|
||||
|
||||
/* Set pipeline to PLAYING state */
|
||||
@@ -359,7 +359,7 @@ static void gst_native_play(JNIEnv *env, jobject thiz) {
|
||||
return;
|
||||
GST_DEBUG ("Setting state to PLAYING");
|
||||
data->target_state = GST_STATE_PLAYING;
|
||||
data->is_live |= (gst_element_set_state(data->pipeline, GST_STATE_PLAYING) == GST_STATE_CHANGE_NO_PREROLL);
|
||||
data->is_live = (gst_element_set_state(data->pipeline, GST_STATE_PLAYING) == GST_STATE_CHANGE_NO_PREROLL);
|
||||
}
|
||||
|
||||
/* Set pipeline to PAUSED state */
|
||||
@@ -369,7 +369,7 @@ static void gst_native_pause(JNIEnv *env, jobject thiz) {
|
||||
return;
|
||||
GST_DEBUG ("Setting state to PAUSED");
|
||||
data->target_state = GST_STATE_PAUSED;
|
||||
data->is_live |=(gst_element_set_state(data->pipeline, GST_STATE_PAUSED) == GST_STATE_CHANGE_NO_PREROLL);
|
||||
data->is_live = (gst_element_set_state(data->pipeline, GST_STATE_PAUSED) == GST_STATE_CHANGE_NO_PREROLL);
|
||||
}
|
||||
|
||||
/* Static class initializer: retrieve method and field IDs */
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.hisharp.gstreamer_player;
|
||||
|
||||
public interface GstCallback {
|
||||
void onStatus(GstLibrary gstInstance, GstStatus gstStatus);
|
||||
void onMessage(GstLibrary gstInstance, String message);
|
||||
void onStatus(GstStatus gstStatus);
|
||||
void onMessage(String message);
|
||||
}
|
||||
|
||||
@@ -75,17 +75,17 @@ public class GstLibrary implements Closeable {
|
||||
private void setMessage(final String message) {
|
||||
if (gstCallback == null) return;
|
||||
if (message.contains("State changed to PAUSED")) {
|
||||
gstCallback.onStatus(this, GstStatus.PAUSE);
|
||||
gstCallback.onStatus(GstStatus.PAUSE);
|
||||
} else if (message.contains("State changed to PLAYING")) {
|
||||
gstCallback.onStatus(this, GstStatus.PLAYING);
|
||||
gstCallback.onStatus(GstStatus.PLAYING);
|
||||
} else if (message.contains("Could not open resource for reading and writing")) {
|
||||
gstCallback.onStatus(this, GstStatus.ERROR_WHEN_OPENING);
|
||||
gstCallback.onStatus(GstStatus.ERROR_WHEN_OPENING);
|
||||
} else if (message.contains("GStreamer encountered a general supporting library error")) {
|
||||
gstCallback.onStatus(this, GstStatus.ERROR);
|
||||
gstCallback.onStatus(GstStatus.ERROR);
|
||||
} else if (message.contains("Unhandled error")) {
|
||||
gstCallback.onStatus(this, GstStatus.ERROR);
|
||||
gstCallback.onStatus(GstStatus.ERROR);
|
||||
}
|
||||
gstCallback.onMessage(this, message);
|
||||
gstCallback.onMessage(message);
|
||||
}
|
||||
|
||||
// Called from native code. Native code calls this once it has created its pipeline and
|
||||
@@ -94,11 +94,13 @@ public class GstLibrary implements Closeable {
|
||||
Log.i ("GStreamer", "GStreamer initialized:");
|
||||
|
||||
if (gstCallback != null) {
|
||||
gstCallback.onStatus(this, GstStatus.READY);
|
||||
gstCallback.onStatus(GstStatus.READY);
|
||||
}
|
||||
|
||||
// Restore previous playing state
|
||||
nativeSetUri (rtspUrl);
|
||||
if (rtspUrl != null) {
|
||||
nativeSetUri(rtspUrl);
|
||||
}
|
||||
}
|
||||
|
||||
// Called from native code when the size of the media changes or is first detected.
|
||||
|
||||
Reference in New Issue
Block a user