1 #include <lib/base/eerror.h>
2 #include <lib/base/object.h>
3 #include <lib/base/ebase.h>
5 #include <lib/service/servicemp3.h>
6 #include <lib/service/service.h>
7 #include <lib/base/init_num.h>
8 #include <lib/base/init.h>
12 eServiceFactoryMP3::eServiceFactoryMP3()
14 ePtr<eServiceCenter> sc;
16 eServiceCenter::getInstance(sc);
18 sc->addServiceFactory(eServiceFactoryMP3::id, this);
20 m_service_info = new eStaticServiceMP3Info();
23 eServiceFactoryMP3::~eServiceFactoryMP3()
25 ePtr<eServiceCenter> sc;
27 eServiceCenter::getInstance(sc);
29 sc->removeServiceFactory(eServiceFactoryMP3::id);
32 DEFINE_REF(eServiceFactoryMP3)
35 RESULT eServiceFactoryMP3::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
38 ptr = new eServiceMP3(ref.path.c_str());
42 RESULT eServiceFactoryMP3::record(const eServiceReference &ref, ePtr<iRecordableService> &ptr)
48 RESULT eServiceFactoryMP3::list(const eServiceReference &, ePtr<iListableService> &ptr)
54 RESULT eServiceFactoryMP3::info(const eServiceReference &ref, ePtr<iStaticServiceInformation> &ptr)
60 // eStaticServiceMP3Info
63 // eStaticServiceMP3Info is seperated from eServiceMP3 to give information
64 // about unopened files.
66 // probably eServiceMP3 should use this class as well, and eStaticServiceMP3Info
67 // should have a database backend where ID3-files etc. are cached.
68 // this would allow listing the mp3 database based on certain filters.
70 DEFINE_REF(eStaticServiceMP3Info)
72 eStaticServiceMP3Info::eStaticServiceMP3Info()
76 RESULT eStaticServiceMP3Info::getName(const eServiceReference &ref, std::string &name)
78 name = "MP3 file: " + ref.path;
82 int eStaticServiceMP3Info::getLength(const eServiceReference &ref)
89 void eServiceMP3::test_end()
91 eDebug("end of mp3!");
95 eServiceMP3::eServiceMP3(const char *filename): filename(filename), test(eApp)
98 eDebug("SERVICEMP3 construct!");
101 eServiceMP3::~eServiceMP3()
103 eDebug("SERVICEMP3 destruct!");
104 if (m_state == stRunning)
108 DEFINE_REF(eServiceMP3);
110 RESULT eServiceMP3::connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)
112 connection = new eConnection((iPlayableService*)this, m_event.connect(event));
116 RESULT eServiceMP3::start()
118 assert(m_state == stIdle);
122 printf("mp3 starts\n");
123 printf("MP3: %s start\n", filename.c_str());
125 CONNECT(test.timeout, eServiceMP3::test_end);
126 m_event(this, evStart);
130 RESULT eServiceMP3::stop()
132 assert(m_state != stIdle);
133 if (m_state == stStopped)
136 printf("MP3: %s stop\n", filename.c_str());
138 m_event(this, evEnd);
142 RESULT eServiceMP3::pause(ePtr<iPauseableService> &ptr) { ptr=this; return 0; }
143 RESULT eServiceMP3::seek(ePtr<iSeekableService> &ptr) { ptr = 0; return -1; }
146 RESULT eServiceMP3::pause() { printf("mp3 pauses!\n"); return 0; }
147 RESULT eServiceMP3::unpause() { printf("mp3 unpauses!\n"); return 0; }
149 RESULT eServiceMP3::info(ePtr<iServiceInformation>&i) { i = this; return 0; }
151 RESULT eServiceMP3::getName(std::string &name)
153 name = "MP3 File: " + filename;
157 eAutoInitPtr<eServiceFactoryMP3> init_eServiceFactoryMP3(eAutoInitNumbers::service+1, "eServiceFactoryMP3");