• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript web-audio-api-player.PlayerCore类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中web-audio-api-player.PlayerCore的典型用法代码示例。如果您正苦于以下问题:TypeScript PlayerCore类的具体用法?TypeScript PlayerCore怎么用?TypeScript PlayerCore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了PlayerCore类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: constructor

    constructor(player: PlayerCore) {

        // compatibility goal: minimum IE11

        this.player = player;

        // buttons box
        this._buttonsBox = document.getElementById('js-buttons-box');

        // slider (html5 input range)
        this._volumeSlider = document.getElementById('js-player-volume') as HTMLInputElement;

        // loading progress bar (html5 input range)
        this._loadingProgressBar = document.getElementById('js-player-loading-progress') as HTMLInputElement;

        // playing progress bar (html5 input range)
        this._playingProgressBar = document.getElementById('js-player-playing-progress') as HTMLInputElement;

        // start listening to events
        this._createListeners();

        // set the initial volume volume to the volume input range
        this._volumeSlider.value = String(this.player.getVolume());

    }
开发者ID:chrisweb,项目名称:web-audio-api-player,代码行数:25,代码来源:ui.ts


示例2: PlayerCore

$(function () {

    let options: ICoreOptions = {
        soundsBaseUrl: 'https://mp3l.jamendo.com/?trackid=',
        playingProgressIntervalTime: 500
    };

    let player = new PlayerCore(options);
    let playerUI = new PlayerUI(player);

    let firstSoundAttributes: ISoundAttributes = {
        sources: '1314412&format=mp31',
        id: 1314412,
        playlistId: 0,
        onLoading: (loadingProgress, maximumValue, currentValue) => {
            console.log('loading: ', loadingProgress, maximumValue, currentValue);
            playerUI.setLoadingProgress(loadingProgress);
        },
        onPlaying: (playingProgress, maximumValue, currentValue) => {
            console.log('playing: ', playingProgress, maximumValue, currentValue);
            playerUI.setPlayingProgress(playingProgress);
        },
        onStarted: (playTimeOffset) => {
            console.log('started', playTimeOffset);
        },
        onPaused: (playTimeOffset) => {
            console.log('paused', playTimeOffset);
        },
        onStopped: (playTimeOffset) => {
            console.log('stopped', playTimeOffset);
        },
        onResumed: (playTimeOffset) => {
            console.log('resumed', playTimeOffset);
        },
        onEnded: (willPlayNext) => {
            console.log('ended', willPlayNext);
            if (!willPlayNext) {
                playerUI.switchPlayerContext('on');
            }
        }
    };

    // add the first song to queue
    let firstSound = player.addSoundToQueue(firstSoundAttributes);

    let secondSoundAttributes: ISoundAttributes = {
        sources: '1214935&format=ogg1',
        id: 1214935,
        playlistId: 0,
        onLoading: (loadingProgress, maximumValue, currentValue) => {
            console.log('loading: ', loadingProgress, maximumValue, currentValue);
            playerUI.setLoadingProgress(loadingProgress);
        },
        onPlaying: (playingProgress, maximumValue, currentValue) => {
            console.log('playing: ', playingProgress, maximumValue, currentValue);
            playerUI.setPlayingProgress(playingProgress);
        },
        onStarted: (playTimeOffset) => {
            console.log('started', playTimeOffset);
        },
        onPaused: (playTimeOffset) => {
            console.log('paused', playTimeOffset);
        },
        onStopped: (playTimeOffset) => {
            console.log('stopped', playTimeOffset);
        },
        onResumed: (playTimeOffset) => {
            console.log('resumed', playTimeOffset);
        },
        onEnded: (willPlayNext) => {
            console.log('ended', willPlayNext);
            if (!willPlayNext) {
                playerUI.switchPlayerContext('on');
            }
        }
    };

    // add another song
    let secondSound = player.addSoundToQueue(secondSoundAttributes);

    

    //let volume = 90;

    //player.setVolume(volume);

    // play first song in the queue
    //player.play();

    // play next song
    //player.play(player.PLAY_SOUND_NEXT);

    // TODO: use the sound to display the loading progress

    // TODO: add two sounds, then play the second one by passing it's id, queue should get rid of first song and immediatly play the second one

    // TODO: add a playlist of multiple songs at once, play some song (not the first one), again queue up until that song should get wiped, then play any previous song by id
    // but as queue won't know that song, we need to trigger some error
    // do this again but this time reset queue and repopulate it, then play the previous song
    // TODO: can we add some playlist support to avoid that the user manually needs to manage the queue? especially to avoid having to reset it when playing earlier song and then rebuild himself?
//.........这里部分代码省略.........
开发者ID:chrisweb,项目名称:web-audio-api-player,代码行数:101,代码来源:bootstrap.ts


示例3: PlayerCore

$(function () {

    let options: ICoreOptions = {
        soundsBaseUrl: 'https://mp3l.jamendo.com/?trackid=',
        playingProgressIntervalTime: 500,
        //volume: 80
    };
    
    let player = new PlayerCore(options);

    player.setVolume(80);

    let visualizerAudioGraph: any = {};

    player.getAudioContext().then((audioContext) => {

        let bufferInterval = 1024;
        let numberOfInputChannels = 1;
        let numberOfOutputChannels = 1;

        // create the audio graph
        visualizerAudioGraph.gainNode = audioContext.createGain();
        visualizerAudioGraph.delayNode = audioContext.createDelay(1);
        visualizerAudioGraph.scriptProcessorNode = audioContext.createScriptProcessor(bufferInterval, numberOfInputChannels, numberOfOutputChannels);
        visualizerAudioGraph.analyserNode = audioContext.createAnalyser();

        // analyser options
        visualizerAudioGraph.analyserNode.smoothingTimeConstant = 0.2;
        visualizerAudioGraph.analyserNode.minDecibels = -100;
        visualizerAudioGraph.analyserNode.maxDecibels = -33;
        visualizerAudioGraph.analyserNode.fftSize = 16384;
        //visualizerAudioGraph.analyserNode.fftSize = 2048;

        // connect the nodes
        visualizerAudioGraph.delayNode.connect(audioContext.destination);
        visualizerAudioGraph.scriptProcessorNode.connect(audioContext.destination);
        visualizerAudioGraph.analyserNode.connect(visualizerAudioGraph.scriptProcessorNode);
        visualizerAudioGraph.gainNode.connect(visualizerAudioGraph.delayNode);

        player.setAudioGraph(visualizerAudioGraph);

    });

    let isPlaying = false;

    // canvas painting loop
    function looper() {

        if (!isPlaying) {
            return;
        } 

        window.webkitRequestAnimationFrame(looper);

        // visualizer
        var initialArray = new Uint8Array(visualizerAudioGraph.analyserNode.frequencyBinCount);

        visualizerAudioGraph.analyserNode.getByteFrequencyData(initialArray);

        console.log(initialArray);

        //var binsArray = transformToVisualBins(initialArray);

        //console.log(binsArray);

        var VisualData = GetVisualBins(initialArray)
        var TransformedVisualData = transformToVisualBins(VisualData)

        console.log(TransformedVisualData);

        ctx.clearRect(0, 0, canvas.width, canvas.height); // Clear the canvas
        ctx.fillStyle = 'red'; // Color of the bars

        for (var y = 0; y < SpectrumBarCount; y++) {

            let bar_x = y * barWidth;
            let bar_width = barWidth;
            let bar_height = TransformedVisualData[y];

            //  fillRect( x, y, width, height ) // Explanation of the parameters below
            //ctx.fillRect(0, 0, canvas.width, canvas.height);
            ctx.fillRect(bar_x, (canvas.height / 2) - bar_height, bar_width, bar_height);

            ctx.fillRect(bar_x, canvas.height / 2, bar_width, bar_height);

        }

    }

    // initialize player ui
    let playerUI = new PlayerUI(player);

    // add songs to player queue
    let firstSoundAttributes: ISoundAttributes = {
        sources: '1314412&format=mp31',
        id: 1314412,
        //sources: '1214935&format=ogg1',
        //id: 1214935,
        playlistId: 0,
        onLoading: (loadingProgress, maximumValue, currentValue) => {
//.........这里部分代码省略.........
开发者ID:chrisweb,项目名称:web-audio-api-player,代码行数:101,代码来源:bootstrap.ts


示例4:

    player.getAudioContext().then((audioContext) => {

        let bufferInterval = 1024;
        let numberOfInputChannels = 1;
        let numberOfOutputChannels = 1;

        // create the audio graph
        visualizerAudioGraph.gainNode = audioContext.createGain();
        visualizerAudioGraph.delayNode = audioContext.createDelay(1);
        visualizerAudioGraph.scriptProcessorNode = audioContext.createScriptProcessor(bufferInterval, numberOfInputChannels, numberOfOutputChannels);
        visualizerAudioGraph.analyserNode = audioContext.createAnalyser();

        // analyser options
        visualizerAudioGraph.analyserNode.smoothingTimeConstant = 0.2;
        visualizerAudioGraph.analyserNode.minDecibels = -100;
        visualizerAudioGraph.analyserNode.maxDecibels = -33;
        visualizerAudioGraph.analyserNode.fftSize = 16384;
        //visualizerAudioGraph.analyserNode.fftSize = 2048;

        // connect the nodes
        visualizerAudioGraph.delayNode.connect(audioContext.destination);
        visualizerAudioGraph.scriptProcessorNode.connect(audioContext.destination);
        visualizerAudioGraph.analyserNode.connect(visualizerAudioGraph.scriptProcessorNode);
        visualizerAudioGraph.gainNode.connect(visualizerAudioGraph.delayNode);

        player.setAudioGraph(visualizerAudioGraph);

    });
开发者ID:chrisweb,项目名称:web-audio-api-player,代码行数:28,代码来源:bootstrap.ts


示例5: _onChangePlayingProgress

    protected _onChangePlayingProgress(event: Event) {

        let rangeElement = event.target as HTMLInputElement;
        let value = parseInt(rangeElement.value);

        this.player.setPosition(value);

    }
开发者ID:chrisweb,项目名称:web-audio-api-player,代码行数:8,代码来源:ui.ts


示例6: _onChangeVolume

    protected _onChangeVolume(event: Event) {

        // styling the html5 range:
        // http://brennaobrien.com/blog/2014/05/style-input-type-range-in-every-browser.html

        let rangeElement = event.target as HTMLInputElement;
        let value = parseInt(rangeElement.value);

        this.player.setVolume(value);

    }
开发者ID:chrisweb,项目名称:web-audio-api-player,代码行数:11,代码来源:ui.ts


示例7: _onClickButtonsBox

    protected _onClickButtonsBox(event: Event) {

        event.preventDefault();

        let $button = event.target as HTMLElement;

        if ($button.localName === 'span') {
            $button = $button.parentElement;
        }

        if ($button.id === 'js-play-pause-button') {

            let playerContext = this._buttonsBox.dataset['playerContext'];

            switch (playerContext) {
                // is playing
                case 'on':
                    this.player.pause();
                    break;
                // is paused
                case 'off':
                    this.player.play();
                    break;
            }

            this.switchPlayerContext(playerContext);

        }

        if ($button.id === 'js-previous-button') {

            this.setPlayingProgress(0);

            let playerContext = this._buttonsBox.dataset['playerContext'];

            if (playerContext === 'off') {

                this.switchPlayerContext(playerContext);

            }

            this.player.play('previous');

        }

        if ($button.id === 'js-next-button') {

            this.setPlayingProgress(0);

            let playerContext = this._buttonsBox.dataset['playerContext'];

            if (playerContext === 'off') {

                this.switchPlayerContext(playerContext);

            }

            this.player.play('next');

        }

        if ($button.id === 'js-shuffle-button') {

            // TODO

        }

        if ($button.id === 'js-repeat-button') {

            // TODO

        }

    }
开发者ID:chrisweb,项目名称:web-audio-api-player,代码行数:74,代码来源:ui.ts



注:本文中的web-audio-api-player.PlayerCore类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript web-push.sendNotification函数代码示例发布时间:2022-05-25
下一篇:
TypeScript wb-shared.logger类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap