-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.cpp
176 lines (151 loc) · 4.04 KB
/
player.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
* File: player.cpp
* Author: rukshan
*
* Created on August 31, 2013, 9:01 AM
*/
#include "player.h"
#include "srtFormat.h"
#include <stdio.h>
#include <stdlib.h>
#include <vlc/vlc.h>
#include <qt4/QtCore/qdebug.h>
#include <qt4/QtCore/qglobal.h>
libvlc_instance_t *inst;
libvlc_media_player_t *mp;
libvlc_media_t *m;
player::player() {
inst = libvlc_new(0, NULL); //constructor
dataObject ob;
ob.object = "file_selector_open";
ob.msg = "/home/rukshan/Oblivion.mp4";
// Notify(ob);
}
player::player(const player& orig) {
}
player::~player() {
}
void player::play() {
if (!mp) { //if player is not load with media
dataObject ob;
ob.object = "player";
ob.msg = "media_explorer_media";
Notify(ob);
return;
}
if (libvlc_media_player_is_playing(mp)) { //if current playing
/* Pause */
// libvlc_media_player_pause(mp);
dataObject ob;
ob.object = "player";
ob.msg = "play";
// Notify(ob);
} else { //if not playing
/* Play again */
dataObject ob;
ob.object = "player";
ob.msg = "pause";
// Notify(ob);
libvlc_media_player_play(mp);
}
}
void player::stop() {
if (mp) { // if player id initialize
// stop playing
libvlc_media_player_stop(mp); //stop the player
// free the media_player
libvlc_media_player_release(mp);
libvlc_release(inst);
mp = NULL;
}
}
int player::getTime() {
if (mp) { // if player is initialise return the time
return libvlc_media_player_get_time(mp);
} else {
return 0;
}
}
int player::getLength() {
if (mp) {// if player is initialise return the media time length
return libvlc_media_player_get_length(mp);
} else {
return 0;
}
}
int player::getPer() {
}
bool player::isPLay() {
if (mp == NULL) { // if player is nnit initialise return false
return false;
} else { // if player is initialise return the whether is somethings playing
return libvlc_media_player_is_playing(mp);
}
}
void player::pause() {
// libvlc_media_player_set_pause(mp,pause());
// pause();
if (mp && libvlc_media_player_is_playing(mp)) {// if player is initialize pause player
libvlc_media_player_pause(mp);
dataObject ob;
ob.object = "player";
ob.msg = "play";
// Notify(ob);
} else {
// exit(EXIT_FAILURE);
}
}
int player::getPosition() {
if (mp) {
float pos = libvlc_media_player_get_position(mp); // if player is initialize return position
return (int) (pos * 1000.0);
} else {
return 0;
}
}
void player::changePosition(int pos) { /* Called on position slider change */
if (mp) // if player is initialize set position of the media
libvlc_media_player_set_position(mp, (float) pos / 1000.0);
}
void player::changeVolume(int val) {
if (mp) // if player is initialize change volume
libvlc_audio_set_volume(mp, val);
}
void player::mute(int val) {
if (mp) {
dataObject ob;
ob.object = "player";
ob.msg = "mute";
if (val == 0) { //if already muted...
this->changeVolume(80);
ob.val = 80;
} else { //else mute volume
this->changeVolume(0);
ob.val = 0;
}
Notify(ob); //notify the command
}
}
int player::setStartTime() {
if (!mp)
return libvlc_media_player_get_time(mp); //return the start time
else
return 0;
}
libvlc_media_player_t* player::getMP() {
return mp; //return the libvlc media player
}
libvlc_media_player_t * player::open(string path) {
//stop();
inst = libvlc_new(0, NULL); //constructor
m = libvlc_media_new_path(inst, path.c_str());
if (!m) {
qDebug("error load");
return NULL;
}
// create a media play playing environment
mp = libvlc_media_player_new_from_media(m);
// no need to keep the media now
libvlc_media_release(m);
return mp;
}