Workaround missing length even with prescan on gestreamer
This commit is contained in:
1 parent
21f6213c1a
commit
62e8d125c9
1 file changed
+12
-9
@@ -69,13 +69,12 @@ int GstreamerAudioStream::Load(const wchar_t* Media)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
Running = true;
|
Running = true;
|
||||||
|
gst_element_set_state(Element, GST_STATE_NULL);
|
||||||
g_object_set(Element, "uri", Media, NULL);
|
g_object_set(Element, "uri", Media, NULL);
|
||||||
g_object_set(Element, "audio-sink", SinkBin, NULL);
|
g_object_set(Element, "audio-sink", SinkBin, NULL);
|
||||||
g_object_set(Element, "flags", GST_PLAY_FLAG_AUDIO, NULL);
|
g_object_set(Element, "flags", GST_PLAY_FLAG_AUDIO, NULL);
|
||||||
|
|
||||||
gst_element_set_state(Element, GST_STATE_PAUSED);
|
gst_element_set_state(Element, GST_STATE_PAUSED);
|
||||||
//gst_bus_timed_pop_filtered(Bus, -1, GST_MESSAGE_ASYNC_DONE);
|
|
||||||
RefreshDuration();
|
|
||||||
|
|
||||||
return ID;
|
return ID;
|
||||||
}
|
}
|
||||||
@@ -84,8 +83,15 @@ int GstreamerAudioStream::Load(const wchar_t* Media)
|
|||||||
int GstreamerAudioStream::Load(const wchar_t* Media, bool Prescan)
|
int GstreamerAudioStream::Load(const wchar_t* Media, bool Prescan)
|
||||||
{
|
{
|
||||||
Load(Media);
|
Load(Media);
|
||||||
if(Prescan)
|
if(Prescan){
|
||||||
gst_bus_timed_pop_filtered(Bus, -1, GST_MESSAGE_ASYNC_DONE);
|
gst_bus_timed_pop_filtered(Bus, -1, GST_MESSAGE_ASYNC_DONE);
|
||||||
|
//Workaround: Waiting for the stream to be loaded (Length>0)
|
||||||
|
for(int i=0;i<40;i++){
|
||||||
|
if(GetLength()>0.f)
|
||||||
|
break;
|
||||||
|
Sleep(5);
|
||||||
|
}
|
||||||
|
}
|
||||||
return ID;
|
return ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,10 +133,7 @@ void GstreamerAudioStream::Play(void)
|
|||||||
{
|
{
|
||||||
PauseStreamAfterFade = false;
|
PauseStreamAfterFade = false;
|
||||||
Running = true;
|
Running = true;
|
||||||
GstStateChangeReturn ret;
|
if(gst_element_set_state(Element, GST_STATE_PLAYING) == GST_STATE_CHANGE_ASYNC)
|
||||||
if(Element)
|
|
||||||
ret = gst_element_set_state(Element, GST_STATE_PLAYING);
|
|
||||||
if(ret == GST_STATE_CHANGE_ASYNC)
|
|
||||||
gst_bus_timed_pop_filtered(Bus, -1, GST_MESSAGE_ASYNC_DONE);
|
gst_bus_timed_pop_filtered(Bus, -1, GST_MESSAGE_ASYNC_DONE);
|
||||||
SetStreamVolume(Volume * 100.0);
|
SetStreamVolume(Volume * 100.0);
|
||||||
}
|
}
|
||||||
@@ -180,7 +183,7 @@ void GstreamerAudioStream::SetStreamVolumeMax(float MaxVolume)
|
|||||||
|
|
||||||
float GstreamerAudioStream::GetLength()
|
float GstreamerAudioStream::GetLength()
|
||||||
{
|
{
|
||||||
if(Duration <= 0)
|
if(Duration <= 0.f)
|
||||||
RefreshDuration();
|
RefreshDuration();
|
||||||
return Duration;
|
return Duration;
|
||||||
}
|
}
|
||||||
@@ -191,7 +194,7 @@ void GstreamerAudioStream::RefreshDuration()
|
|||||||
{
|
{
|
||||||
gint64 time = -1000;
|
gint64 time = -1000;
|
||||||
if(gst_element_query_duration(Element, GST_FORMAT_TIME, &time))
|
if(gst_element_query_duration(Element, GST_FORMAT_TIME, &time))
|
||||||
Duration = (gfloat)((gdouble)(time/GST_SECOND));
|
Duration = (gfloat)((gdouble)time/GST_SECOND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user