add playlists
[enigma2.git] / lib / service / servicemp3.cpp
1 #include <lib/base/eerror.h>
2 #include <lib/base/object.h>
3 #include <lib/base/ebase.h>
4 #include <string>
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>
9
10 // eServiceFactoryMP3
11
12 eServiceFactoryMP3::eServiceFactoryMP3(): ref(0)
13 {
14         ePtr<eServiceCenter> sc;
15         
16         eServiceCenter::getInstance(sc);
17         if (sc)
18                 sc->addServiceFactory(eServiceFactoryMP3::id, this);
19 }
20
21 eServiceFactoryMP3::~eServiceFactoryMP3()
22 {
23         ePtr<eServiceCenter> sc;
24         
25         eServiceCenter::getInstance(sc);
26         if (sc)
27                 sc->removeServiceFactory(eServiceFactoryMP3::id);
28 }
29
30 DEFINE_REF(eServiceFactoryMP3)
31
32         // iServiceHandler
33 RESULT eServiceFactoryMP3::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
34 {
35                 // check resources...
36         ptr = new eServiceMP3(ref.path.c_str());
37         return 0;
38 }
39
40 RESULT eServiceFactoryMP3::record(const eServiceReference &ref, ePtr<iRecordableService> &ptr)
41 {
42         ptr=0;
43         return -1;
44 }
45
46 RESULT eServiceFactoryMP3::list(const eServiceReference &, ePtr<iListableService> &ptr)
47 {
48         ptr=0;
49         return -1;
50 }
51
52 // eServiceMP3
53
54
55 void eServiceMP3::test_end()
56 {
57         eDebug("end of mp3!");
58         stop();
59 }
60
61 eServiceMP3::eServiceMP3(const char *filename): ref(0), filename(filename), test(eApp)
62 {
63         m_state = stIdle;
64         eDebug("SERVICEMP3 construct!");
65 }
66
67 eServiceMP3::~eServiceMP3()
68 {
69         eDebug("SERVICEMP3 destruct!");
70         if (m_state == stRunning)
71                 stop();
72 }
73
74 DEFINE_REF(eServiceMP3);        
75
76 RESULT eServiceMP3::connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)
77 {
78         connection = new eConnection(this, m_event.connect(event));
79         return 0;
80 }
81
82 RESULT eServiceMP3::start()
83 {
84         assert(m_state == stIdle);
85         
86         m_state = stRunning;
87
88         printf("mp3 starts\n");
89         printf("MP3: %s start\n", filename.c_str());
90         test.start(1000, 1);
91         CONNECT(test.timeout, eServiceMP3::test_end);
92         m_event(this, evStart);
93         return 0;
94 }
95
96 RESULT eServiceMP3::stop()
97 {
98         assert(m_state != stIdle);
99         if (m_state == stStopped)
100                 return -1;
101         test.stop();
102         printf("MP3: %s stop\n", filename.c_str());
103         m_state = stStopped;
104         m_event(this, evEnd);
105         return 0;
106 }
107
108 RESULT eServiceMP3::getIPausableService(ePtr<iPauseableService> &ptr) { ptr=this; return 0; }
109
110                 // iPausableService
111 RESULT eServiceMP3::pause() { printf("mp3 pauses!\n"); return 0; }
112 RESULT eServiceMP3::unpause() { printf("mp3 unpauses!\n"); return 0; }
113
114 RESULT eServiceMP3::getIServiceInformation(ePtr<iServiceInformation>&i) { i = this; return 0; }
115
116 RESULT eServiceMP3::getName(eString &name)
117 {
118         name = "MP3 File: " + filename;
119         return 0;
120 }
121
122 eAutoInitPtr<eServiceFactoryMP3> init_eServiceFactoryMP3(eAutoInitNumbers::service+1, "eServiceFactoryMP3");