aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Ziener <mziener@lavabit.com>2010-10-14 14:42:53 +0200
committerMarco Ziener <mziener@lavabit.com>2010-10-14 14:42:53 +0200
commitffc23bfadbd6094e4f441ef8b2b783cb28d1451b (patch)
tree8aabac6b1bf6e7d30020ae5bc9f838144eff819d
parentef4e9912fcb98fedd6926dd93deb9bdbaaa244e3 (diff)
parentd3e9b13d93d2b64cefdbff408bebc4e0be01f0a9 (diff)
downloaderlang-ffc23bfadbd6094e4f441ef8b2b783cb28d1451b.tar.gz
erlang-ffc23bfadbd6094e4f441ef8b2b783cb28d1451b.tar.xz
erlang-ffc23bfadbd6094e4f441ef8b2b783cb28d1451b.zip
Merge branch 'master' of ssh://git.animux.de/erlang
-rw-r--r--.gitignore1
-rw-r--r--server/dispatcher.erl2
-rw-r--r--server/media.erl25
3 files changed, 20 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore
index 5f61fbd..7a5856f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
*.beam
folien.pdf
+server/Mnesia.*
diff --git a/server/dispatcher.erl b/server/dispatcher.erl
index 4f1f58b..9b4c61b 100644
--- a/server/dispatcher.erl
+++ b/server/dispatcher.erl
@@ -5,6 +5,8 @@ start() ->
code:purge(server),
code:load_abs("../common/server"),
+ spawn(media, init, []),
+
case server:start(dis, dispatcher) of
true ->
io:format("Server started... ~n"),
diff --git a/server/media.erl b/server/media.erl
index cbd9328..ddbed78 100644
--- a/server/media.erl
+++ b/server/media.erl
@@ -56,13 +56,14 @@ insert(Artist, Title, Filepath) ->
% 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}.
+%search_best(_,_,_) -> {"Allison Crowe", "Northern Lights"}.
+search_best([Head|Rest], Max_Votes, Track) ->
+ if
+ ((Max_Votes =< Head#track.votes) and (Head#track.locked == false)) ->
+ 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.
@@ -90,7 +91,15 @@ play(Artist, Title, Callback) ->
[Head|_] = ask(Artist, Title),
{_, 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]),
+
+ % lock the song
+ F = fun() ->
+ New = Head#track{locked = 1},
+ mnesia:write(New)
+ end,
+ mnesia:transaction(F),
+
+ io:format("playing: ~s, Artist: ~s~n", [Title, Artist]),
receive
{Port, {exit_status, 0}} -> start_playing();
{Port, {exit_status, S}} -> throw({commandfailed, S})