aboutsummaryrefslogtreecommitdiffstats
path: root/server/media.erl
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--server/media.erl23
1 files changed, 14 insertions, 9 deletions
diff --git a/server/media.erl b/server/media.erl
index fd4a1b6..fb1d951 100644
--- a/server/media.erl
+++ b/server/media.erl
@@ -11,11 +11,6 @@
-record(track, {title, artist, votes, locked, filepath }).
-% With which application do we play mp3s?
-
-player(path) ->
- {ok, ["/usr/bin/env", "mplayer", "-quiet", path]}.
-
% Before this module becomes usable, we must initialize it with the following steps:
% 1. Initialize the mnesiadatabase and create the table within it.
% 2. Parse the mp3s in the working directory and add them to the database
@@ -44,17 +39,26 @@ read_files([],Total,Fail) -> io:format("Total: ~w, Failed: ~w~n", [Total, Fail])
% Our Runloop to play music all the time, play waits on exit_status
start_playing() ->
- {Artist, Title} = search_best(),
+ {Artist, Title} = search_best(media:all(), 0,0),
play(Artist, Title, "muh").
+
+%insert The Track into the database
insert(Artist, Title, Filepath) ->
F = fun() ->
-
mnesia:write(#track{artist = Artist, title = Title, votes = 0, locked = false, filepath = Filepath})
end,
mnesia:transaction(F).
-search_best() -> {"Allison Crowe", "Northern Lights"}.
+% search the track with the highest votes and return {Artist, Title}
+
+search_best(_,_,_) -> {"Allison Crowe", "Northern Lights"}.
+%search_best([Head|Rest], Max_Votes, Track) ->
+% if (Max_Votes < Head#track.votes) and (Head#track.locked == 0) ->
+% search_best(Rest, Head#track.votes, Head);
+% true -> search_best(Rest, Max_Votes, Track)
+% end;
+%search_best([], _, Track) -> {Track#track.Artist, Track#track.Title}.
% We want to query in order to simplify the next calls.
@@ -80,8 +84,9 @@ all() ->
play(Artist, Title, Callback) ->
[Head|_] = ask(Artist, Title),
- {_, _, _, _, _, Fp} = Head,
+ {_, Title, Artist, _, _, Fp} = Head,
Port = erlang:open_port({spawn_executable, "/usr/bin/mplayer"}, [{args, [Fp]}, exit_status]),
+ io:format("playing: ~w, Artist: ~w~n", [Title, Artist]),
receive
{Port, {exit_status, 0}} -> start_playing();
{Port, {exit_status, S}} -> throw({commandfailed, S})