From 6db16da47ad7605d49a4a357306956e6e6f8d49e Mon Sep 17 00:00:00 2001 From: Dario Casalinuovo Date: Fri, 8 Jul 2016 22:56:55 +0200 Subject: [PATCH] playfile: Make it to accept URLs along with files * Users can now use it to play web radios. * Also useful to show easy is to adapt old code. --- src/bin/playsound/Jamfile | 2 +- src/bin/playsound/playfile.cpp | 32 ++++++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/bin/playsound/Jamfile b/src/bin/playsound/Jamfile index 75593cff33..d4256dcff6 100644 --- a/src/bin/playsound/Jamfile +++ b/src/bin/playsound/Jamfile @@ -2,7 +2,7 @@ SubDir HAIKU_TOP src bin playsound ; BinCommand playfile : playfile.cpp - : be media [ TargetLibsupc++ ] + : be bnetapi media [ TargetLibsupc++ ] ; BinCommand playsound : diff --git a/src/bin/playsound/playfile.cpp b/src/bin/playsound/playfile.cpp index 6927d6527c..833ceccbee 100644 --- a/src/bin/playsound/playfile.cpp +++ b/src/bin/playsound/playfile.cpp @@ -7,18 +7,20 @@ #include #include #include +#include #include +#include + #include #include #include #include -#include thread_id reader = -1; sem_id finished = -1; -BMediaTrack *playTrack; +BMediaTrack* playTrack; media_format playFormat; -BSoundPlayer *sp = 0; +BSoundPlayer* sp = 0; volatile bool interrupt = false; void @@ -49,14 +51,28 @@ int main(int argc, char *argv[]) { if (argc != 2) { - fprintf(stderr, "Usage:\n %s \n", argv[0]); + fprintf(stderr, "Usage:\n %s \n", argv[0]); return 1; } - + + BUrl url; + bool isUrl = false; entry_ref ref; - if (get_ref_for_path(argv[1], &ref)!=B_OK) - return 2; - BMediaFile *playFile = new BMediaFile(&ref); + + if (get_ref_for_path(argv[1], &ref) != B_OK) { + url.SetUrlString(argv[1]); + if (url.IsValid()) + isUrl = true; + else + return 2; + } + + BMediaFile* playFile; + if (isUrl) + playFile = new BMediaFile(url); + else + playFile = new BMediaFile(&ref); + if (playFile->InitCheck()