forked from rauversion/rauversion-phx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from rauversion/new-form
New form
- Loading branch information
Showing
30 changed files
with
959 additions
and
409 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,74 @@ | ||
// app/javascript/controllers/audio_controller.js | ||
import { Controller } from "@hotwired/stimulus" | ||
import WaveSurfer from 'wavesurfer' | ||
|
||
export default class extends Controller { | ||
static targets = ['player', 'play', 'pause'] | ||
static targets = ['player', 'play', 'pause', 'playicon', 'pauseicon'] | ||
|
||
static values = { | ||
height: String | ||
} | ||
|
||
_wave = null | ||
|
||
initialize() {} | ||
|
||
connect() { | ||
if(!this.data.get('url')) { | ||
console.error("skip player, no url found!") | ||
return | ||
} | ||
console.log("INIT WAVEEE") | ||
this.wave() | ||
this.initWave() | ||
} | ||
disconnect() { | ||
this._wave && this._wave.destroy() | ||
} | ||
disconnect() {} | ||
|
||
wave(){ | ||
if (this._wave == undefined) { | ||
this._wave = WaveSurfer.create({ | ||
container: this.playerTarget, | ||
backend: 'MediaElement', | ||
waveColor: 'grey', | ||
progressColor: 'tomato', | ||
height: this.heightValue || 70, | ||
//fillParent: false, | ||
barWidth: 2, | ||
//barHeight: 10, // the height of the wave | ||
barGap: null, | ||
minPxPerSec: 2, | ||
pixelRatio: 10, | ||
cursorWidth: 1, | ||
cursorColor: "lightgray", | ||
normalize: false, | ||
responsive: true, | ||
fillParent: true | ||
}) | ||
|
||
initWave() { | ||
this._wave = WaveSurfer.create({ | ||
container: this.playerTarget, | ||
backend: 'MediaElement', | ||
waveColor: 'grey', | ||
progressColor: 'tomato', | ||
height: this.heightValue || 70, | ||
//fillParent: false, | ||
barWidth: 2, | ||
//barHeight: 10, // the height of the wave | ||
barGap: null, | ||
minPxPerSec: 2, | ||
pixelRatio: 10, | ||
cursorWidth: 1, | ||
cursorColor: "lightgray", | ||
normalize: false, | ||
responsive: true, | ||
fillParent: true | ||
}) | ||
|
||
console.log("VAUES",this.data.get('peaks').length) | ||
const data = JSON.parse(this.data.get('peaks')) // [0.45,0.54,0.43,0.61,0.47,0.71,0.42,0.59,0.39,0.59,0.41,0.57,0.39,0.59,0.41,0.56,0.43,0.57,0.44,0.59,0.45,0.6,0.44,0.56,0.42,0.63,0.4,0.63,0.36] | ||
this._wave.load(this.data.get('url'), data) | ||
console.log("VAUES",this.data.get('peaks').length) | ||
const data = JSON.parse(this.data.get('peaks')) | ||
this._wave.load(this.data.get('url'), data) | ||
|
||
window.tt = this | ||
var _this = this | ||
|
||
_this.pauseTarget.style.display = 'none' | ||
this._wave.on('pause', function () { | ||
_this.playiconTarget.style.display = 'block' | ||
_this.pauseiconTarget.style.display = 'none' | ||
}) | ||
this._wave.on('play', function () { | ||
_this.playiconTarget.style.display = 'none' | ||
_this.pauseiconTarget.style.display = 'block' | ||
}) | ||
} | ||
|
||
var _this = this | ||
// var that = this | ||
_this.pauseTarget.style.display = 'none' | ||
this._wave.on('pause', function () { | ||
_this.playTarget.style.display = 'block' | ||
_this.pauseTarget.style.display = 'none' | ||
}) | ||
this._wave.on('play', function () { | ||
_this.playTarget.style.display = 'none' | ||
_this.pauseTarget.style.display = 'block' | ||
}) | ||
} | ||
wave(){ | ||
return this._wave | ||
} | ||
|
||
play(){ | ||
this.wave().play() | ||
this.wave().playPause() | ||
} | ||
|
||
pause(){ | ||
this.wave().pause() | ||
this.wave().stop() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.