aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorMarco Ziener <mziener@lavabit.com>2010-10-14 14:59:59 +0200
committerMarco Ziener <mziener@lavabit.com>2010-10-14 14:59:59 +0200
commitf274c57728163f77abf3b2afb18ffe6041b6720f (patch)
treedf279fb40383e995afea63e794f93892c8860aee /server
parent6f2124d3e49257ef0d275b83e7c2b4f84f1a3bde (diff)
downloaderlang-f274c57728163f77abf3b2afb18ffe6041b6720f.tar.gz
erlang-f274c57728163f77abf3b2afb18ffe6041b6720f.tar.xz
erlang-f274c57728163f77abf3b2afb18ffe6041b6720f.zip
Random Improvements
Diffstat (limited to 'server')
-rw-r--r--server/media.erl20
1 files changed, 18 insertions, 2 deletions
diff --git a/server/media.erl b/server/media.erl
index 755d965..b3b8e0f 100644
--- a/server/media.erl
+++ b/server/media.erl
@@ -1,7 +1,7 @@
-module(media).
-export([init/0,insert/3, ask/2, all/0, play/3, vote/2, devote/2, lock_process/2]).
-define(TESTPATTERN, "../ac/*.mp3").
--define(TIMEOUT, 10000).
+-define(TIMEOUT, 1000000).
% Since we are not willing to calculate and deliver all the id3 tags everytime they are requested,
% we try to get something persistent with mnesia.
@@ -91,7 +91,14 @@ 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]),
- spawn(media, lock_process,[Artist,Title]),
+
+ % 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();
@@ -121,6 +128,15 @@ devote(Artist, Title) ->
end,
mnesia:transaction(F).
+reset_votes(Artist, Title) ->
+ F = fun() ->
+ [Head|_] = ask(Artist, Title),
+ New = Head#track{votes = 0},
+ mnesia:write(New)
+ end,
+ mnesia:transaction(F).
+
+
lock(Artist, Title) ->
F = fun() ->
[Head|_] = ask(Artist, Title),