aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/media.erl18
1 files changed, 16 insertions, 2 deletions
diff --git a/server/media.erl b/server/media.erl
index 91fc34b..fd4a1b6 100644
--- a/server/media.erl
+++ b/server/media.erl
@@ -26,7 +26,8 @@ init() ->
mnesia:start(),
mnesia:create_table(track, [{index, [y]}, {attributes, record_info(fields, track)}]),
read_files(filelib:wildcard(?TESTPATTERN),0,0),
- io:format("Initialisation of mnesia successful.\n").
+ io:format("Initialisation of mnesia successful.\n"),
+ start_playing().
read_files([FN|Rest],Total,Fail) ->
case id3v2:read_file(FN) of
@@ -41,6 +42,11 @@ read_files([],Total,Fail) -> io:format("Total: ~w, Failed: ~w~n", [Total, Fail])
% Basic insertion of entrys into the database. Some entries are left out because they are 0 or false.
+% Our Runloop to play music all the time, play waits on exit_status
+start_playing() ->
+ {Artist, Title} = search_best(),
+ play(Artist, Title, "muh").
+
insert(Artist, Title, Filepath) ->
F = fun() ->
@@ -48,6 +54,9 @@ insert(Artist, Title, Filepath) ->
end,
mnesia:transaction(F).
+search_best() -> {"Allison Crowe", "Northern Lights"}.
+
+
% We want to query in order to simplify the next calls.
ask(Artist, Title) ->
F = fun() ->
@@ -72,7 +81,12 @@ all() ->
play(Artist, Title, Callback) ->
[Head|_] = ask(Artist, Title),
{_, _, _, _, _, Fp} = Head,
- Port = erlang:open_port({spawn_executable, "/usr/bin/mplayer"}, [{args, [Fp]}]).
+ Port = erlang:open_port({spawn_executable, "/usr/bin/mplayer"}, [{args, [Fp]}, exit_status]),
+ receive
+ {Port, {exit_status, 0}} -> start_playing();
+ {Port, {exit_status, S}} -> throw({commandfailed, S})
+ end.
+
% Of course we need a query to find out whats actually the most wished for track.
% We will do it by requesting all the records from the database and then iteramte over just taking a look at the vote