Commit 58da01b1 authored by daFischer's avatar daFischer

Audio controls and fullscreen work, except for seeking

parent 7803c731
emBuild/TTT/
\ No newline at end of file
emBuild/TTT/
emBuild/fileplayer.data
......@@ -64,14 +64,19 @@ Audio::Audio(const char* path) {
failed=false;
}
void Audio::play(){
//Play the audio file
printf("play1\n");
alSourcePlay(source);
printf("play2\n");
printf("Start playing for %d ms\n",getDuration());
//The audio is playing!
void Audio::togglePlay(){
ALint state;
alGetSourcei(source, AL_SOURCE_STATE, &state);
if (state != AL_PLAYING)
{
//Play the audio file
alSourcePlay(source);
printf("play2\n");
}
else
{
alSourcePause(source);
}
}
int Audio::getPosition()
......@@ -87,15 +92,18 @@ int Audio::getPosition()
}
/*bool Audio::setPosition(int time)
void Audio::setPosition(int pos)
{
ALfloat pos=(ALfloat)pos/1000.0;
alSourcef(source, AL_SEC_OFFSET, pos);
ALfloat time=(ALfloat)pos/1000.0;
alSourcef(source, AL_SEC_OFFSET, time);
if(alGetError()== AL_NO_ERROR)
return true;
else
return false;
}*/
printf("Audio.cpp: set Position error");
}
void Audio::changeVolume(float volume){
ALfloat v=volume;
alSourcef(source,AL_GAIN,v);
}
int Audio::getDuration()
{
......
......@@ -33,11 +33,12 @@ using namespace std;
class Audio: public AudioInterface{
public:
Audio(const char*);
void play();
void togglePlay();
int getPosition();
//bool setPosition(int time);
void setPosition(int pos);
int getDuration();
bool hasFailed();
void changeVolume(float volume);
private:
bool failed;
......
......@@ -11,7 +11,7 @@ AudioInterface::AudioInterface(){
}
void AudioInterface::play(){
void AudioInterface::togglePlay(){
}
int AudioInterface::getDuration(){
......@@ -22,6 +22,12 @@ int AudioInterface::getPosition(){
return 0;
}
void AudioInterface::setPosition(int pos){
}
void AudioInterface::changeVolume(float volume){
}
bool AudioInterface::hasFailed(){
return true;
}
......@@ -16,10 +16,12 @@ class AudioInterface {
public:
AudioInterface();
virtual void play();
virtual void togglePlay();
virtual int getPosition();
virtual void setPosition(int pos);
virtual int getDuration();
virtual bool hasFailed();
virtual void changeVolume(float volume);
};
......
......@@ -16,9 +16,9 @@ AudioJS::AudioJS() {
printf("Duration: %d min\n",duration/60000);
}
void AudioJS::play(){
void AudioJS::togglePlay(){
EM_ASM(
x_play();
x_togglePlay();
);
}
......@@ -26,6 +26,13 @@ int AudioJS::getDuration(){
return duration;
}
void AudioJS::setPosition(int pos){
EM_ASM_INT({
x_setDuration($0);
return 0;
},pos);
}
int AudioJS::getPosition(){
return EM_ASM_INT({
return x_getPosition();
......@@ -36,4 +43,10 @@ bool AudioJS::hasFailed(){
return false;
}
void AudioJS::changeVolume(float volume){
EM_ASM_INT({
x_changeVolume($0);
},volume);
}
#endif
......@@ -22,10 +22,12 @@ using namespace std;
class AudioJS: public AudioInterface{
public:
AudioJS();
void play();
void togglePlay();
int getPosition();
void setPosition(int pos);
int getDuration();
bool hasFailed();
void changeVolume(float volume);
private:
int duration;
......
/*
* File: Controls.cpp
* Author: user
*
* Created on July 13, 2014, 6:40 PM
*/
#include "Controls.h"
bool mouseOnFullScreenButton;
Controls::Controls(Video* video, AudioInterface* audio) {
this->video=video;
this->audio=audio;
ProtocolPreferences prefs;
//TODO: might make these relative to video's height
timeLineHeight=16;
height=32;
y=prefs.framebufferHeight - height;
width=prefs.framebufferWidth;
timeLineClicked=false;
timeLineChange=-1;
volumeClicked=false;
volume=1;
mouseOnFullScreenButton=false;
#ifdef EMSCRIPTEN
EM_ASM_INT({
x_setupFullScreen($0, $1);
}, 48, height);
#endif
}
void Controls::registerClick(Uint16 mx, Uint16 my){
if(my<y-timeLineHeight)
return;
if(my<y)
{
timeLineClicked=true;
}
else
{
if(mx<48)
togglePlay();
else if(mx>=width-48)
toggleFullscreen();
else if(mx<=128 && mx>=64)
volumeClicked=true;
}
}
void Controls::registerMouseUp(){
timeLineClicked=false;
volumeClicked=false;
}
void Controls::registerMovement(Uint16 mx, Uint16 my) {
if(timeLineClicked)
timeLineChange=mx;
if(volumeClicked)
changeVolume(max(min((float)(mx-64),(float)64),(float)0)/64);
//#ifdef EMSCRIPTEN
mouseOnFullScreenButton=(mx>=width-48 && my>=y);
//#endif
}
//#ifdef EMSCRIPTEN
extern "C" bool getOnFullScreenButton(){
return mouseOnFullScreenButton;
}
//#endif
void Controls::update(){
if(!timeLineClicked && timeLineChange>=0)
{
skipTo(audio->getDuration()*timeLineChange/width);
timeLineChange=-1;
}
draw();
}
void Controls::togglePlay(){
audio->togglePlay();
}
void Controls::toggleFullscreen(){
#ifndef EMSCRIPTEN
video->toggleFullscreen();
#endif
}
void Controls::draw(){
SDL_Surface *screen=video->getScreen();
//main body
SDL_Rect rect = {0, y, width, height};
SDL_FillRect(screen, &rect, 0xff000000);
//play/pause
redefineRect(&rect, 0, y, 48, height);
SDL_FillRect(screen, &rect, 0xff338844);
//volume
redefineRect(&rect, 64, y, 64, height);
SDL_FillRect(screen, &rect, 0xff338844);
redefineRect(&rect, 64, y, (int)(volume*64.0), height);
SDL_FillRect(screen, &rect, 0xff0000aa);
//fullscreen button
redefineRect(&rect, width-48, y, 48, height);
SDL_FillRect(screen, &rect, 0xff338844);
//timeLine background
redefineRect(&rect, 0, y-timeLineHeight+2, width, timeLineHeight-2);
SDL_FillRect(screen, &rect, 0xff333333);
//timeLine foreground
redefineRect(&rect, 0, y-timeLineHeight, width*audio->getPosition()/audio->getDuration(), timeLineHeight);
SDL_FillRect(screen, &rect, 0xffaa0000);
SDL_UpdateRect(screen, 0,y-timeLineHeight,width,height+timeLineHeight);
}
void Controls::redefineRect(SDL_Rect* rect, int x, int y, int w, int h){
rect->x=x;
rect->y=y;
rect->w=w;
rect->h=h;
}
void Controls::skipTo(int position){
}
void Controls::changeVolume(float volume){
this->volume=volume;
audio->changeVolume(volume);
}
/*
* File: Controls.h
* Author: user
*
* Created on July 13, 2014, 6:40 PM
*/
#ifndef CONTROLS_H
#define CONTROLS_H
#include "AudioInterface.h"
#include "Video.h"
#include "ProtocolPreferences.h"
#include <stdio.h>
#include <SDL/SDL.h>
#ifdef EMSCRIPTEN
#include <emscripten/emscripten.h>
#endif
using namespace std;
class Controls {
public:
Controls(Video* video, AudioInterface* audio);
void update();
void registerClick(Uint16 mx, Uint16 my);
void registerMouseUp();
void registerMovement(Uint16 mx, Uint16 my);
private:
Video* video;
AudioInterface* audio;
int width, height;
int timeLineHeight;
bool timeLineClicked;
int timeLineChange; //For when the user seeks through the video
bool volumeClicked;
float volume;
int y;
void togglePlay();
void toggleFullscreen();
void skipTo(int position);
void draw();
void redefineRect(SDL_Rect* rect, int x, int y, int w, int h);
void changeVolume(float volume);
};
//#ifdef EMSCRIPTEN
extern "C" bool getOnFullScreenButton();
//#endif
#endif /* CONTROLS_H */
......@@ -7,6 +7,7 @@
#include "Player.h"
#include "AudioJS.h"
#include "Controls.h"
Player *player;
......@@ -39,11 +40,13 @@ Player::Player(const char* cpath, const char* cfilename) {
return;
}
audio->play();
controls=new Controls(video,audio);
audio->togglePlay();
printf("start looping\n");
#ifdef EMSCRIPTEN
emscripten_set_main_loop(emLoop,30,1);
emscripten_set_main_loop(emLoop,0,0);
#else
quit = false;
while(true)
......@@ -63,6 +66,7 @@ void Player::loop()
SDL_Event event;
while (SDL_PollEvent(&event))
{
if (event.type == SDL_KEYDOWN) {
switch(event.key.keysym.sym) {
#ifndef EMSCRIPTEN
......@@ -74,7 +78,16 @@ void Player::loop()
default:
break;
}
}
else if(event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT)
controls->registerClick(event.button.x,event.button.y);
else if(event.type == SDL_MOUSEBUTTONUP && event.button.button == SDL_BUTTON_LEFT)
controls->registerMouseUp();
else if(event.type == SDL_MOUSEMOTION)
controls->registerMovement(event.motion.x,event.motion.y);
}
controls->update();
}
void emLoop()
......
......@@ -27,6 +27,7 @@
#include "Audio.h"
#endif
#include "Video.h"
#include "Controls.h"
using namespace std;
......@@ -39,6 +40,7 @@ public:
private:
AudioInterface *audio;
Video *video;
Controls* controls;
bool paused;
const char* filename;
#ifndef EMSCRIPTEN
......
......@@ -6,7 +6,6 @@
*/
#include "Video.h"
#include "Message.h"
Video::Video(const char* path) {
......@@ -64,6 +63,18 @@ void Video::update(int zeit)
}
}
SDL_Surface* Video::getScreen(){
return screen;
}
void Video::toggleFullscreen(){
return; //doesn't work yet, but not really important
{
printf("toggle fullscreen %d,%d\n",screen->flags,screen->flags & SDL_FULLSCREEN);
screen=SDL_SetVideoMode(screen->w, screen->h, screen->format->BitsPerPixel, screen->flags ^ SDL_FULLSCREEN);
}
}
bool readServerInit(Inflater* in)
{
ProtocolPreferences prefs;
......
......@@ -32,6 +32,8 @@ public:
//Video(const Video& orig);
virtual ~Video();
void update(int zeit);
SDL_Surface* getScreen();
void toggleFullscreen();
bool failed;
......
build/Debug/GNU-Linux-x86/Controls.o: Controls.cpp Controls.h \
AudioInterface.h Video.h Inflater.h SizedArray.h ProtocolPreferences.h \
Message.h Constants.h
Controls.h:
AudioInterface.h:
Video.h:
Inflater.h:
SizedArray.h:
ProtocolPreferences.h:
Message.h:
Constants.h:
build/Debug/GNU-Linux-x86/Player.o: Player.cpp Player.h AudioInterface.h \
Audio.h Video.h Inflater.h SizedArray.h ProtocolPreferences.h Message.h \
Constants.h AudioJS.h
Constants.h Controls.h AudioJS.h
Player.h:
......@@ -20,4 +20,6 @@ Message.h:
Constants.h:
Controls.h:
AudioJS.h:
build/Debug/GNU-Linux-x86/main.o: main.cpp main.h Player.h \
AudioInterface.h Audio.h Video.h Inflater.h SizedArray.h \
ProtocolPreferences.h Message.h Constants.h
ProtocolPreferences.h Message.h Constants.h Controls.h
main.h:
......@@ -21,3 +21,5 @@ ProtocolPreferences.h:
Message.h:
Constants.h:
Controls.h:
......@@ -8,18 +8,52 @@ var x_getSeek=function(){
}
return false;
}
var x_getPosition=function(){
return x_audio.currentTime*1000;
}
var x_setPosition=function(pos){
x_audio.currentTime=pos/1000;
}
var x_getDuration=function(){
return x_audio.duration*1000;
}
var x_play=function(){
x_audio.play();
var x_togglePlay=function(){
if(x_audio.paused)
x_audio.play();
else
x_audio.pause();
}
var x_fullscreen=false;
var x_canvas=document.getElementById('canvas');
var x_rect;
var x_onFull;
var x_setupFullScreen=function(w, h){
x_rect=x_canvas.getBoundingClientRect();
x_onFull=Module.cwrap('getOnFullScreenButton', 'bool');
x_canvas.addEventListener('click', function(e) {
if(x_onFull())
{
var x_canvas_div=document.getElementById('canvas_div');
if(x_fullscreen)
document.mozCancelFullScreen();
//x_canvas_div.exitFullscreen();
else
x_canvas_div.mozRequestFullScreen();
x_fullscreen=!x_fullscreen;
}
}, false);
}
var x_changeVolume=function(volume){
x_audio.volume=volume;
}
var x_audioLoaded=function(){
}
/*var x_setPosition=function(pos){
x_audio.currentTime=pos/1000;
}*/
......@@ -6,9 +6,9 @@ DIR=../
MESSAGES= $(DIR)DeleteAllAnnotation.cpp $(DIR)EmptyMessage.cpp $(DIR)HextileMessage.cpp $(DIR)Message.cpp $(DIR)WhiteboardMessage.cpp
ZSRC = libz/adler32.c libz/compress.c libz/crc32.c libz/deflate.c libz/gzclose.c libz/gzlib.c libz/gzread.c \
libz/gzwrite.c libz/infback.c libz/inffast.c libz/inflate.c libz/inftrees.c libz/trees.c libz/uncompr.c libz/zutil.c
SRC= $(DIR)AudioInterface.cpp $(DIR)AudioJS.cpp $(DIR)ColorConverter.cpp $(DIR)Constants.cpp $(DIR)Inflater.cpp $(DIR)Player.cpp $(DIR)ProtocolPreferences.cpp $(DIR)SizedArray.cpp $(DIR)Video.cpp $(DIR)main.cpp $(MESSAGES)
SRC= $(DIR)AudioInterface.cpp $(DIR)AudioJS.cpp $(DIR)ColorConverter.cpp $(DIR)Constants.cpp $(DIR)Controls.cpp $(DIR)Inflater.cpp $(DIR)Player.cpp $(DIR)ProtocolPreferences.cpp $(DIR)SizedArray.cpp $(DIR)Video.cpp $(DIR)main.cpp $(MESSAGES)
EXPORT=-s "EXPORTED_FUNCTIONS=['_main', '_on_play', '_on_pause', '_set_path']"
EXPORT=-s "EXPORTED_FUNCTIONS=['_main', '_on_play', '_on_pause', '_set_path', '_getOnFullScreenButton']"
PRELOAD= --preload-file TTT/Diskrete_Strukturen_2013_11_26_a/Diskrete_Strukturen_2013_11_26.ttt
#STATICLIB= libz.bc
......
......@@ -13,7 +13,7 @@
.emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; }
div.emscripten { text-align: center; }
div.emscripten_border { border: 1px solid black; }
div.emscripten_border { border: 1px solid black; display: inline-block;}
/* the canvas *must not* have any border or padding, or mouse coords will be wrong */
canvas.emscripten {
border: 0px none;
......@@ -23,7 +23,7 @@
margin:0px none;
padding:0px none;
float:bottom;
width: 100%;
width:100%;
}
#emscripten_logo {
......@@ -1206,7 +1206,7 @@
<span id='controls'>
<span><input type="checkbox" id="resize">Resize canvas</span>
<span><input type="checkbox" id="pointerLock" checked>Lock/hide mouse pointer &nbsp;&nbsp;&nbsp;</span>
<span><input type="button" value="Fullscreen" onclick="Module.requestFullScreen(document.getElementById('pointerLock').checked, document.getElementById('resize').checked)">
<span><input type="button" value="Fullscreen" onclick="Module.requestFullScreen(document.getElementById('pointerLock').checked, false)">
</span>
</span>
......@@ -1215,9 +1215,9 @@
</div>
<div class="emscripten_border">
<div class="emscripten_border" id="canvas_div">
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()"></canvas>
<audio class="emscripten" id ="audioplayer" onloadeddata="x_audioLoaded()" onseeking="x_seeked=true;" controls>
<audio class="emscripten" id ="audioplayer" onloadeddata="x_audioLoaded()" onseeking="x_seeked=true;" >
<source src="TTT/Diskrete_Strukturen_2013_11_26_a/Diskrete_Strukturen_2013_11_26.ogg" type="audio/ogg">
<source src="TTT/Diskrete_Strukturen_2013_11_26_a/Diskrete_Strukturen_2013_11_26.mp3" type="audio/mp3">
<source src="TTT/Diskrete_Strukturen_2013_11_26_a/Diskrete_Strukturen_2013_11_26.wav" type="audio/wav">
......
This diff is collapsed.
......@@ -40,6 +40,7 @@ OBJECTFILES= \
${OBJECTDIR}/AudioJS.o \
${OBJECTDIR}/ColorConverter.o \
${OBJECTDIR}/Constants.o \
${OBJECTDIR}/Controls.o \
${OBJECTDIR}/DeleteAllAnnotation.o \
${OBJECTDIR}/EmptyMessage.o \
${OBJECTDIR}/HextileMessage.o \
......@@ -102,6 +103,11 @@ ${OBJECTDIR}/Constants.o: Constants.cpp
${RM} "$@.d"
$(COMPILE.cc) -g -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/Constants.o Constants.cpp
${OBJECTDIR}/Controls.o: Controls.cpp
${MKDIR} -p ${OBJECTDIR}
${RM} "$@.d"
$(COMPILE.cc) -g -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/Controls.o Controls.cpp
${OBJECTDIR}/DeleteAllAnnotation.o: DeleteAllAnnotation.cpp
${MKDIR} -p ${OBJECTDIR}
${RM} "$@.d"
......
......@@ -40,6 +40,7 @@ OBJECTFILES= \
${OBJECTDIR}/AudioJS.o \
${OBJECTDIR}/ColorConverter.o \
${OBJECTDIR}/Constants.o \
${OBJECTDIR}/Controls.o \
${OBJECTDIR}/DeleteAllAnnotation.o \
${OBJECTDIR}/EmptyMessage.o \
${OBJECTDIR}/HextileMessage.o \
......@@ -102,6 +103,11 @@ ${OBJECTDIR}/Constants.o: Constants.cpp
${RM} "$@.d"
$(COMPILE.cc) -O2 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/Constants.o Constants.cpp
${OBJECTDIR}/Controls.o: Controls.cpp
${MKDIR} -p ${OBJECTDIR}
${RM} "$@.d"
$(COMPILE.cc) -O2 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/Controls.o Controls.cpp
${OBJECTDIR}/DeleteAllAnnotation.o: DeleteAllAnnotation.cpp
${MKDIR} -p ${OBJECTDIR}
${RM} "$@.d"
......
......@@ -6,8 +6,10 @@
projectFiles="true">
<itemPath>Audio.h</itemPath>
<itemPath>AudioInterface.h</itemPath>
<itemPath>AudioJS.h</itemPath>
<itemPath>ColorConverter.h</itemPath>
<itemPath>Constants.h</itemPath>
<itemPath>Controls.h</itemPath>
<itemPath>DeleteAllAnnotation.h</itemPath>
<itemPath>EmptyMessage.h</itemPath>
<itemPath>HextileMessage.h</itemPath>
......@@ -31,8 +33,10 @@
</logicalFolder>
<itemPath>Audio.cpp</itemPath>
<itemPath>AudioInterface.cpp</itemPath>
<itemPath>AudioJS.cpp</itemPath>
<itemPath>ColorConverter.cpp</itemPath>
<itemPath>Constants.cpp</itemPath>
<itemPath>Controls.cpp</itemPath>
<itemPath>DeleteAllAnnotation.cpp</itemPath>
<itemPath>EmptyMessage.cpp</itemPath>
<itemPath>HextileMessage.cpp</itemPath>
......@@ -51,8 +55,6 @@
kind="IMPORTANT_FILES_FOLDER">
<itemPath>Makefile</itemPath>
</logicalFolder>
<itemPath>AudioJS.cpp</itemPath>
<itemPath>AudioJS.h</itemPath>
</logicalFolder>
<projectmakefile>Makefile</projectmakefile>
<confs>
......@@ -98,6 +100,10 @@
</item>
<item path="Constants.h" ex="false" tool="3" flavor2="0">
</item>
<item path="Controls.cpp" ex="false" tool="1" flavor2="0">
</item>
<item path="Controls.h" ex="false" tool="3" flavor2="0">
</item>
<item path="DeleteAllAnnotation.cpp" ex="false" tool="1" flavor2="0">
</item>
<item path="DeleteAllAnnotation.h" ex="false" tool="3" flavor2="0">
......@@ -183,6 +189,10 @@
</item>
<item path="Constants.h" ex="false" tool="3" flavor2="0">
</item>
<item path="Controls.cpp" ex="false" tool="1" flavor2="0">
</item>
<item path="Controls.h" ex="false" tool="3" flavor2="0">
</item>
<item path="DeleteAllAnnotation.cpp" ex="false" tool="1" flavor2="0">
</item>
<item path="DeleteAllAnnotation.h" ex="false" tool="3" flavor2="0">
......
......@@ -7,13 +7,20 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Player.h</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Audio.cpp</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Player.cpp</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Inflater.cpp</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Inflater.h</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/main.h</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Controls.cpp</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Audio.h</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/main.h</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Video.cpp</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Video.h</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/AudioInterface.cpp</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Player.h</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Controls.h</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/Player.cpp</file>
<file>file:/home/user/NetBeansProjects/TTTPlayer/AudioJS.cpp</file>