aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--server/media.erl22
1 files changed, 15 insertions, 7 deletions
diff --git a/server/media.erl b/server/media.erl
index 10fed99..fbdaa7e 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, 1000000).
+-define(TIMEOUT, 100000000).
% 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.
@@ -22,9 +22,12 @@ init() ->
mnesia:start(),
mnesia:create_table(track, [{attributes, record_info(fields, track)}]),
read_files(filelib:wildcard(?TESTPATTERN),0,0),
- io:format("Initialisation of mnesia successful.\n"),
- start_playing(),
- io:format("Starting to play music\n").
+ 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
+% inserts the songs into the Database
read_files([FN|Rest],Total,Fail) ->
case id3v2:read_file(FN) of
@@ -37,8 +40,6 @@ read_files([FN|Rest],Total,Fail) ->
end;
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() ->
@@ -56,17 +57,24 @@ 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 == false)) ->
search_best(Rest, Head#track.votes, Head);
true -> search_best(Rest, Max_Votes, Track)
end;
+search_best([], 0, 0) -> reset_all(all());
search_best([], _, Track) -> {Track#track.artist, Track#track.title}.
+% if nothing is playable anymore just reset them and start playing again...
+
+reset_all([Head|Rest) ->
+ unlock(Head#track.artist, Head#track.title),
+ reset_all(Rest);
+reset_all([]) -> ok.
% We want to query in order to simplify the next calls.
+
ask(Artist, Title) ->
F = fun() ->
mnesia:match_object({track, Title, Artist, '_', '_', '_'})