You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
local function http_result(self, _id, response, extra)
9874
9880
if response.status == 200 or response.status == 206 then
9881
+
-- Successful request
9875
9882
local relative_path = self.filename
9876
9883
local range = response.headers['content-range'] -- content-range = "bytes 0-16383/103277"
9877
9884
local rstart, rend, filesize = parse_range(range)
9878
-
9879
-
-- Create the Defold resource, "partial" will enable the streaming mode
9885
+
-- Create the Defold resource
9886
+
-- "partial" will enable the streaming mode
9880
9887
print("Creating resource", relative_path)
9881
9888
local hash = resource.create_sound_data(relative_path, { data = response.response, filesize = filesize, partial = true })
9882
-
9883
-
go.set(self.component, "sound", hash) -- override the resource data on the component
9884
-
sound.play(self.component) -- start the playing
9889
+
-- send "play_sound" to the component
9890
+
play_sound(self, hash)
9885
9891
end
9886
9892
end
9887
9893
@@ -9896,10 +9902,36 @@ end
9896
9902
9897
9903
## Resource providers
9898
9904
9899
-
You can of course use other means to load the initial chunk of the sound file. The important thing to remember is that the rest of the chunks are loaded from the resource system and it's resource providers.
9905
+
You can use other means to load the initial chunk of the sound file. The important thing to remember is that the rest of the chunks are loaded from the resource system and its resource providers. In this example, we add a new (http) file provider by adding a live update mount, by calling using [liveupdate.add_mount()](https://defold.com/ref/liveupdate/#liveupdate.add_mount).
9906
+
9907
+
You can find a working example in [https://github.com/defold/example-sound-streaming](https://github.com/defold/example-sound-streaming).
9900
9908
9901
-
In this example, we have added a new file provider by adding a live update mount, by calling using [liveupdate.add_mount()](https://defold.com/ref/liveupdate/#liveupdate.add_mount).
9909
+
```lua
9910
+
-- See http_result() from above example
9911
+
9912
+
local function load_web_sound(base_url, relative_path)
go.set(self.component, "sound", hash) -- override the resource data on the component
68
-
sound.play(self.component) -- start the playing
73
+
-- send "play_sound" to the component
74
+
play_sound(self, hash)
69
75
end
70
76
end
71
77
@@ -80,10 +86,36 @@ end
80
86
81
87
## Resource providers
82
88
83
-
You can of course use other means to load the initial chunk of the sound file. The important thing to remember is that the rest of the chunks are loaded from the resource system and it's resource providers.
89
+
You can use other means to load the initial chunk of the sound file. The important thing to remember is that the rest of the chunks are loaded from the resource system and its resource providers. In this example, we add a new (http) file provider by adding a live update mount, by calling using [liveupdate.add_mount()](/ref/liveupdate/#liveupdate.add_mount).
90
+
91
+
You can find a working example in [https://github.com/defold/example-sound-streaming](https://github.com/defold/example-sound-streaming).
84
92
85
-
In this example, we have added a new file provider by adding a live update mount, by calling using [liveupdate.add_mount()](/ref/liveupdate/#liveupdate.add_mount).
0 commit comments