Passed
Push — master ( 998e10...1efe83 )
by Marcel
06:10
created

js/viewer/viewer.js (13 issues)

1
/**
2
 * Audio Player
3
 *
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later. See the LICENSE.md file.
6
 *
7
 * @author Marcel Scherello <[email protected]>
8
 * @author Sebastian Doell <[email protected]>
9
 * @copyright 2016-2019 Marcel Scherello
10
 * @copyright 2015 Sebastian Doell
11
 */
12
13
/* global soundManager */
14
// OK because ./js/soundmanager2.js is sourced before in html
15
16
'use strict';
0 ignored issues
show
Use the function form of "use strict".
Loading history...
17
18
var audioPlayer = {
19
    mime: null,
20
    file: null,
21
    location: null,
22
    player: null,
23
    dir: null
24
};
25
26
function playFile(file, data) {
27
    file = encodeURIComponent(file);
28
    audioPlayer.file = file;
29
    audioPlayer.dir = data.dir;
30
    var token = ($('#sharingToken').val() !== undefined) ? $('#sharingToken').val() : '';
0 ignored issues
show
$ does not seem to be defined.
Loading history...
31
    var dirLoad = data.dir.substr(1);
32
    if (dirLoad !== '') {
33
        dirLoad = dirLoad + '/';
34
    }
35
    if (token !== '') {
36
        audioPlayer.location = OC.generateUrl('apps/audioplayer/getpublicaudiostream?token={token}&file={file}', {
0 ignored issues
show
OC does not seem to be defined.
Loading history...
37
            'token': token,
38
            'file': dirLoad + file
39
        }, {escape: false});
40
    } else {
41
        audioPlayer.location = OC.generateUrl('apps/audioplayer/getaudiostream?file={file}', {'file': dirLoad + file}, {escape: true});
0 ignored issues
show
OC does not seem to be defined.
Loading history...
42
    }
43
    audioPlayer.mime = data.$file.attr('data-mime');
44
    data.$file.find('.thumbnail').html('<i class="ioc ioc-volume-up"  style="color:#fff;margin-left:5px; text-align:center;line-height:32px;text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;font-size: 24px;"></i>');
45
46
    if (audioPlayer.player === null) {
47
        soundManager.setup({
48
            onready: function () {
49
                audioPlayer.player = soundManager.createSound({
50
                    id: data.$file.attr('data-id'),
51
                    url: audioPlayer.location
52
                });
53
                audioPlayer.player.play();
54
            }
55
        });
56
    } else {
57
        audioPlayer.player.stop();
58
        $('#filestable').find('.thumbnail i.ioc-volume-up').hide();
0 ignored issues
show
$ does not seem to be defined.
Loading history...
59
        //$('#filestable').find('.thumbnail i.ioc-play').show();
60
        audioPlayer.player = null;
61
    }
62
}
63
64
function registerFileActions() {
65
    var mime_array = ['audio/mpeg', 'audio/mp4', 'audio/m4b', 'audio/ogg', 'audio/wav', 'audio/flac'];
66
    //var stream_array = ['audio/mpegurl', 'audio/x-scpls', 'application/xspf+xml'];
67
    //mime_array = mime_array.concat(stream_array);
68
69
    soundManager.setup({
70
        onready: function () {
71
            audioPlayer.player = soundManager.createSound({});
72
73
            var can_play = soundManager.html5;
74
            var mime;
75
            var icon_url = OC.imagePath('core', 'actions/sound');
0 ignored issues
show
OC does not seem to be defined.
Loading history...
76
            for (var i = 0; i < mime_array.length; i++) {
77
                if (can_play[mime_array[i]] === true) {
78
                    mime = mime_array[i];
79
                    OCA.Files.fileActions.registerAction({
0 ignored issues
show
OCA does not seem to be defined.
Loading history...
80
                        name: 'audio',
81
                        displayName: 'audio',
82
                        mime: mime,
83
                        permissions: OC.PERMISSION_READ,
0 ignored issues
show
OC does not seem to be defined.
Loading history...
84
                        icon: icon_url,
85
                        actionHandler: playFile
86
                    });
87
                    OCA.Files.fileActions.setDefault(mime, 'audio');
0 ignored issues
show
OCA does not seem to be defined.
Loading history...
88
                }
89
            }
90
            audioPlayer.player = null;
91
        }
92
    });
93
}
94
95
$(document).ready(function () {
0 ignored issues
show
$ does not seem to be defined.
Loading history...
document does not seem to be defined.
Loading history...
96
    if (typeof OCA !== 'undefined' && typeof OCA.Files !== 'undefined' && typeof OCA.Files.fileActions !== 'undefined' && $('#header').hasClass('share-file') === false) {
0 ignored issues
show
$ does not seem to be defined.
Loading history...
OCA does not seem to be defined.
Loading history...
97
        registerFileActions();
98
    }
99
    return true;
100
});