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.
This commit is contained in:
@@ -2,7 +2,7 @@ SubDir HAIKU_TOP src bin playsound ;
|
|||||||
|
|
||||||
BinCommand playfile :
|
BinCommand playfile :
|
||||||
playfile.cpp
|
playfile.cpp
|
||||||
: be media [ TargetLibsupc++ ]
|
: be bnetapi media [ TargetLibsupc++ ]
|
||||||
;
|
;
|
||||||
|
|
||||||
BinCommand playsound :
|
BinCommand playsound :
|
||||||
|
|||||||
@@ -7,18 +7,20 @@
|
|||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <MediaFile.h>
|
#include <MediaFile.h>
|
||||||
#include <MediaTrack.h>
|
#include <MediaTrack.h>
|
||||||
|
#include <OS.h>
|
||||||
#include <SoundPlayer.h>
|
#include <SoundPlayer.h>
|
||||||
|
#include <Url.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <OS.h>
|
|
||||||
|
|
||||||
thread_id reader = -1;
|
thread_id reader = -1;
|
||||||
sem_id finished = -1;
|
sem_id finished = -1;
|
||||||
BMediaTrack *playTrack;
|
BMediaTrack* playTrack;
|
||||||
media_format playFormat;
|
media_format playFormat;
|
||||||
BSoundPlayer *sp = 0;
|
BSoundPlayer* sp = 0;
|
||||||
volatile bool interrupt = false;
|
volatile bool interrupt = false;
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -49,14 +51,28 @@ int
|
|||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (argc != 2) {
|
if (argc != 2) {
|
||||||
fprintf(stderr, "Usage:\n %s <filename>\n", argv[0]);
|
fprintf(stderr, "Usage:\n %s <filename or url>\n", argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BUrl url;
|
||||||
|
bool isUrl = false;
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
if (get_ref_for_path(argv[1], &ref)!=B_OK)
|
|
||||||
return 2;
|
if (get_ref_for_path(argv[1], &ref) != B_OK) {
|
||||||
BMediaFile *playFile = new BMediaFile(&ref);
|
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()<B_OK) {
|
if (playFile->InitCheck()<B_OK) {
|
||||||
delete playFile;
|
delete playFile;
|
||||||
return 2;
|
return 2;
|
||||||
|
|||||||
Reference in New Issue
Block a user