aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/media.erl22
1 files changed, 11 insertions, 11 deletions
diff --git a/server/media.erl b/server/media.erl
index 14aa53e..8c60f10 100644
--- a/server/media.erl
+++ b/server/media.erl
@@ -3,8 +3,8 @@
-define(TESTPATTERN, "../ac/*.mp3").
-define(TIMEOUT, 100000000).
-%This module is responsible for the management of the music database.
-%It keeps track of playlist items with their current voting and locked/unlocked status
+%This module is responsible for the management of the music database.
+%It keeps track of playlist items with their current voting and locked/unlocked status
%and automatically selects the next song with the highest vote count to play back.
% Since we are not willing to calculate and deliver all the id3 tags everytime they are requested,
@@ -29,8 +29,8 @@ init() ->
io:format("Initialisation of mnesia successful.~n"),
io:format("Starting to play music~n"),
start_playing().
-
-% uses the algorithm of Brendon Hogger to split the id3-tags and
+
+% uses the algorithm of Brendon Hogger to split the id3-tags and
% inserts the songs into the Database
read_files([FN|Rest],Total,Fail) ->
@@ -61,12 +61,12 @@ insert(Artist, Title, Filepath) ->
% 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
-% variable, so it is like list of integers. In case no tracks were voted for we just take the first track we find and play it.
+% variable, so it is like list of integers. In case no tracks were voted for we just take the first track we find and play it.
% Of course it is locked afterwards so another will be choosen.
-search_best([Head|Rest], Max_Votes, Track) ->
- if
+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)
@@ -109,7 +109,7 @@ play(Artist, Title) ->
Port = erlang:open_port({spawn_executable, "/usr/bin/mplayer"}, [{args, [Fp]}, exit_status]),
reset_votes(Artist, Title),
spawn(media, lock_process, [Artist, Title]),
-
+
io:format("playing: ~s, Artist: ~s~n", [Title, Artist]),
receive
{Port, {exit_status, 0}} -> cldb:update_votes(), start_playing();
@@ -149,7 +149,7 @@ reset_votes(Artist, Title) ->
mnesia:write(New)
end,
mnesia:transaction(F).
-
+
%locks a song so it can't be played again or voted for for that time.
lock(Artist, Title) ->
F = fun() ->
@@ -172,10 +172,10 @@ unlock(Artist, Title) ->
% If all songs are locked, all will be unlocked.
lock_process(Artist, Title) ->
lock(Artist, Title),
- receive
+ receive
after ?TIMEOUT ->
unlock(Artist, Title) end.
-
+