123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- <div class="alert alert-warning">
- <span class="fa fa-warning fa-fw" aria-hidden="true"></span> {{ 'WamiNeedFilename'|get_lang }}
- </div>
- <div id="record-audio-recordrtc" class="row text-center">
- <form>
- <div class="row">
- <div class="col-sm-4 col-sm-offset-4">
- <div class="form-group">
- <span class="fa fa-microphone fa-5x fa-fw" aria-hidden="true"></span>
- <span class="sr-only">{{ 'RecordAudio'|get_lang }}</span>
- </div>
- <div class="form-group">
- <input type="text" name="audio_title" id="audio-title-rtc" class="form-control" placeholder="{{ 'InputNameHere'|get_lang }}">
- </div>
- </div>
- </div>
- <div class="text-center">
- <div class="form-groups">
- <button class="btn btn-primary" type="button" id="btn-start-record">
- <span class="fa fa-circle fa-fw" aria-hidden="true"></span> {{ 'StartRecordingAudio'|get_lang }}
- </button>
- <button class="btn btn-success" type="button" id="btn-stop-record" disabled>
- <span class="fa fa-square fa-fw" aria-hidden="true"></span> {{ 'StopRecordingAudio'|get_lang }}
- </button>
- </div>
- </div>
- </form>
- </div>
- <div class="row" id="record-audio-wami">
- <div class="col-sm-3 col-sm-offset-3">
- <br>
- <form>
- <div class="form-group">
- <input type="text" name="audio_title" id="audio-title-wami" class="form-control" placeholder="{{ 'InputNameHere'|get_lang }}">
- </div>
- <div class="form-group text-center">
- <button class="btn btn-primary" type="button" id="btn-activate-wami">
- <span class="fa fa-check fa-fw" aria-hidden=""></span> {{ 'Activate'|get_lang }}
- </button>
- </div>
- </form>
- </div>
- <div class="col-sm-3">
- <div id="record-audio-wami-container" class="wami-container"></div>
- </div>
- </div>
- <script>
- $(document).on('ready', function () {
- function useRecordRTC() {
- $('#record-audio-recordrtc').show();
- var audioTitle = '';
- var mediaConstraints = {audio: true},
- recordRTC = null,
- btnStart = $('#btn-start-record'),
- btnStop = $('#btn-stop-record');
- btnStart.on('click', function () {
- audioTitle = $('#audio-title-rtc').val();
- if (!$.trim(audioTitle)) {
- return;
- }
- navigator.getUserMedia = navigator.getUserMedia ||
- navigator.mozGetUserMedia ||
- navigator.webkitGetUserMedia;
- if (navigator.getUserMedia) {
- navigator.getUserMedia(mediaConstraints, successCallback, errorCallback);
- } else if (navigator.mediaDevices.getUserMedia) {
- navigator.mediaDevices.getUserMedia(mediaConstraints)
- .then(successCallback).error(errorCallback);
- }
- function successCallback(stream) {
- recordRTC = RecordRTC(stream, {
- numberOfAudioChannels: 1,
- type: 'audio'
- });
- recordRTC.startRecording();
- $('#audio-title-rtc').prop('readonly', true);
- btnStop.prop('disabled', false);
- btnStart.prop('disabled', true);
- }
- function errorCallback(error) {
- alert(error.message);
- }
- });
- btnStop.on('click', function () {
- if (!recordRTC) {
- return;
- }
- recordRTC.stopRecording(function (audioURL) {
- var recordedBlob = recordRTC.getBlob(),
- fileName = audioTitle,
- fileExtension = '.' + recordedBlob.type.split('/')[1];
- var formData = new FormData();
- formData.append('audio_blob', recordedBlob, audioTitle + fileExtension);
- formData.append('audio_dir', '{{ directory }}');
- $.ajax({
- url: '{{ _p.web_ajax }}record_audio_rtc.ajax.php',
- data: formData,
- processData: false,
- contentType: false,
- type: 'POST',
- success: function (fileURL) {
- if (!fileURL) {
- return;
- }
- window.location.reload();
- }
- });
- $('#audio-title-rtc').prop('readonly', false);
- btnStop.prop('disabled', true);
- btnStart.prop('disabled', false);
- });
- });
- }
- function useWami() {
- $('#record-audio-wami').show();
- var audioTitle = '';
- $('#btn-activate-wami').on('click', function (e) {
- e.preventDefault();
- audioTitle = $('#audio-title-wami').val();
- if (!$.trim(audioTitle)) {
- return;
- }
- $('#audio-title-wami').prop('readonly', true);
- $(this).prop('disabled', true);
- Wami.setup({
- id : "record-audio-wami-container",
- onReady : setupGUI,
- swfUrl: '{{ _p.web_lib }}wami-recorder/Wami.swf'
- });
- });
- function setupGUI() {
- var gui = new Wami.GUI({
- id : 'record-audio-wami-container',
- singleButton : true,
- recordUrl : '{{ _p.web_ajax }}record_audio_wami.ajax.php?' + $.param({
- waminame: audioTitle + '.wav',
- wamidir: '{{ directory }}',
- wamiuserid: {{ user_id }}
- }),
- buttonUrl : '{{ _p.web_lib }}wami-recorder/buttons.png',
- buttonNoUrl: '{{ _p.web_img }}blank.gif',
- onRecordFinish: function() {
- window.location.reload();
- }
- });
- gui.setPlayEnabled(false);
- }
- }
- $('#record-audio-recordrtc, #record-audio-wami').hide();
- var webRTCIsEnabled = navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.getUserMedia ||
- navigator.mediaDevices.getUserMedia;
- if (webRTCIsEnabled) {
- useRecordRTC();
- return;
- }
- useWami();
- });
- </script>
|