aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2010-10-14 13:49:26 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2010-10-14 13:49:26 +0200
commit81de759a91c959d8e5fa1c88d5f44e1110d66d55 (patch)
tree0820bcb209196bfc682ce2b63e2df8defdf164c2
parent7b0bf7c8b3e57bbeadfb8e23ebe43696acf0bfe0 (diff)
parent10419216d9c2c3d71997229d605df9321a94c113 (diff)
downloaderlang-81de759a91c959d8e5fa1c88d5f44e1110d66d55.tar.gz
erlang-81de759a91c959d8e5fa1c88d5f44e1110d66d55.tar.xz
erlang-81de759a91c959d8e5fa1c88d5f44e1110d66d55.zip
Merge branch 'master' of ssh://git.animux.de/erlang
-rw-r--r--server/media.erl22
1 files changed, 14 insertions, 8 deletions
diff --git a/server/media.erl b/server/media.erl
index 0a99275..1957bdb 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,16 +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.
@@ -79,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})