-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add audio support and single playback in attributes. Readme update. #23
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -15,7 +15,9 @@ class ARMarker extends HTMLElement { | |||||||
src: this.content, | ||||||||
scale: {x: 1, y: 1, z: 1}, | ||||||||
position: {x: 0, y: 0, z: 0}, | ||||||||
rotation: {x: 0, y: 0, z: 0} | ||||||||
rotation: {x: 0, y: 0, z: 0}, | ||||||||
loop: 0, | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change these integers (0 or 1) to really booleans (true or false). |
||||||||
audio: 0, | ||||||||
} | ||||||||
}else { | ||||||||
// case where the content was specified as ar-content | ||||||||
|
@@ -24,7 +26,9 @@ class ARMarker extends HTMLElement { | |||||||
src: arContent.getAttribute('src'), | ||||||||
scale: this.stringToVec3(arContent.getAttribute('scale')), | ||||||||
position: this.stringToVec3(arContent.getAttribute('position')), | ||||||||
rotation: this.stringToVec3(arContent.getAttribute('rotation')) | ||||||||
rotation: this.stringToVec3(arContent.getAttribute('rotation')), | ||||||||
loop: arContent.getAttribute('loop'), | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here you can use something inline if:
Suggested change
|
||||||||
audio: arContent.getAttribute('audio') | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
} | ||||||||
} | ||||||||
} | ||||||||
|
@@ -50,12 +54,22 @@ class ARMarker extends HTMLElement { | |||||||
}else{ | ||||||||
this.video = document.createElement("video"); | ||||||||
this.video.src = this.contentProps.src; | ||||||||
|
||||||||
this.video.loop = true; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the previous changes here you can do:
Suggested change
|
||||||||
if(this.contentProps.loop == 0) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the previous changes, these lines can be removed |
||||||||
{ | ||||||||
this.video.loop = false; | ||||||||
} | ||||||||
|
||||||||
this.video.muted = true; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
if(this.contentProps.audio == 1) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the previous changes, these lines can be removed |
||||||||
{ | ||||||||
this.video.muted = false; | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
const self = this | ||||||||
|
||||||||
arController.addEventListener('getMarker', (ev) => { | ||||||||
// supress wanings | ||||||||
console.warn = function(){} | ||||||||
|
@@ -70,13 +84,17 @@ class ARMarker extends HTMLElement { | |||||||
let ctx = self.textureCanvas.getContext('2d'); | ||||||||
ctx.clearRect(0, 0, self.textureCanvas.width, self.textureCanvas.height); | ||||||||
ctx.drawImage(self.image, 0, 0, self.textureCanvas.width, self.textureCanvas.height); | ||||||||
|
||||||||
} else if(ev.data.marker.id == markerId) { | ||||||||
if(self.video.ended != 0 && self.contentProps.loop == 0) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem with this line is when the video ended if I have to update the page to play again. When the marker goes out of the camera vision and then returns, the video doesn't play again. This is the expected behavior? |
||||||||
{ | ||||||||
return; | ||||||||
} | ||||||||
self.video.play(); | ||||||||
(function loop() { | ||||||||
let ctx = self.textureCanvas.getContext('2d'); | ||||||||
if (!self.video.paused && !self.video.ended) { | ||||||||
ctx.clearRect(0,0, self.textureCanvas.width, self.textureCanvas.height); | ||||||||
ctx.clearRect(0,0, self.textureCanvas.width, self.textureCanvas.height); | ||||||||
ctx.drawImage(self.video, 0, 0, self.textureCanvas.width, self.textureCanvas.height); | ||||||||
texture.needsUpdate = true; | ||||||||
setTimeout(loop, 1000 / 30); // drawing at 30fps | ||||||||
|
@@ -116,7 +134,7 @@ class ARMarker extends HTMLElement { | |||||||
// converts a string in the format "1 1 1" to an object like {x: 1, y: 1, z: 1} | ||||||||
stringToVec3(str) { | ||||||||
let split = str.split(" ") | ||||||||
|
||||||||
return { | ||||||||
x: split[0] || 0, | ||||||||
y: split[1] || 0, | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a more semantic style, I think "0" or "1" could be changed to "true" or "false".