From 204e06b2af3f8d4f41298967aa1ce4b9e0838227 Mon Sep 17 00:00:00 2001 From: Michael Wittig Date: Thu, 14 Oct 2010 12:23:06 +0200 Subject: runloop and wait on song end implemented --- server/media.erl | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'server') 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 -- cgit v1.2.3