-
-
Save singularitypostman/2c9622872f151df55501d1d9901975a0 to your computer and use it in GitHub Desktop.
Erlang Data Streaming
This file contains hidden or 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
| -module(streaming). | |
| -export([stream_data/1, out/1, stream_from_file/3]). | |
| out(_Arg) -> | |
| _Pid = spawn_link(?MODULE, stream_data, [self()]), | |
| {streamcontent, "audio/mp3", <<>>}. | |
| stream_data(Pid) -> | |
| File = "/home/erlang/erlang-talk/audio.mp3", | |
| FileHDL = open_file(File), | |
| stream_from_file(Pid, FileHDL, 1). | |
| stream_from_file(Pid, File, I) -> | |
| Result = file:read(File, 4096), | |
| case Result of | |
| {ok, Data} -> | |
| yaws_api:stream_chunk_deliver_blocking(Pid,Data), | |
| streaming:stream_from_file(Pid, File, I+1); | |
| eof -> | |
| yaws_api:stream_chunk_end(Pid); | |
| {error,Reason}-> | |
| error_logger:error_msg("~p:~p Error ~p ~n", | |
| [?MODULE, ?LINE, Reason]) | |
| end. | |
| open_file(File) -> | |
| {ok, IoDevice} = file:open(File, | |
| [read, binary]), | |
| IoDevice. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment