#StackBounty: #javascript #canvas #optimization #webgl #mediarecorder Optimize performance of 1920×1080 canvas recording

Bounty: 50

I would like to make a basic canvas-recorder using the MediaRecorder API to record a webGL (or other) canvas.

I want the final video to be 1920×1080 size (even if the actual resolution is lower, AKA i’m fine with it being scaled up).

The problem is that when I try to load a 1920×1080 canvas and screen record it with WebGL, the results are very jittery and choppy, like, extremely (even though it does record it, choppyness and all).
All I want is the finished size of the video to be 1920×1080, even if it’s actually lower quality, and I need it to play in real time in a browser, without being choppy. So:

  1. Is there any way to make a webGL canvas a bigger size, while keeping the same performance it would have with a smaller size?

  2. Is there a way for the mediarecorder API to record a video that has a higher resolution than the stream (in this case, a canvas stream) that it is currently capturing?


Get this bounty!!!

#StackBounty: #reactjs #performance #webgl #webgl2 #deck.gl Display: none on Deck.gl React component causes huge performance issue

Bounty: 150

EDIT: This issue is specific to this setup. Please use the code from here if you wish to help. Thanks!

I am using Deck.gl with react to display a map. When I try to hide the map with display: none it starts to freeze up my whole computer. I have worked around this by using visibility: collapse instead, but I would like to know why display: none causes this problem.

The console starts perpetually filling up with warnings:

luma: Device pixel ratio clamped context.js:202:84
Error: WebGL warning: clear: Requested size 21535x8218 was too large, but resize to 10767x4109 succeeded. bundle.min.js line 15214 > eval:32:60490
Error: WebGL warning: drawElements: Drawing to a destination rect smaller than the viewport rect. (This warning will only be given once) bundle.min.js line 15214 > eval:32:191695
Error: WebGL warning: drawingBufferWidth: Requested size 21535x8218 was too large, but resize to 10767x4109 succeeded. bundle.min.js line 7141 > eval:201:9
Error: WebGL warning: clear: Requested size 20020x7637 was too large, but resize to 10010x3818 succeeded. bundle.min.js line 15214 > eval:32:60490
Error: WebGL warning: drawingBufferWidth: Requested size 20020x7637 was too large, but resize to 10010x3818 succeeded. bundle.min.js line 7141 > eval:201:9
Error: WebGL warning: clear: Requested size 18609x7099 was too large, but resize to 9304x3549 succeeded. bundle.min.js line 15214 > eval:32:60490
Error: WebGL warning: drawingBufferWidth: Requested size 18609x7099 was too large, but resize to 9304x3549 succeeded. bundle.min.js line 7141 > eval:201:9
Error: WebGL warning: clear: Requested size 17297x6598 was too large, but resize to 8648x3299 succeeded. bundle.min.js line 15214 > eval:32:60490
Source map error: Error: NetworkError when attempting to fetch resource.
Resource URL: webpack:///./node_modules/@luma.gl/webgl/dist/esm/context/context.js?
Source Map URL: context.js.map
Error: WebGL warning: drawingBufferWidth: Requested size 17297x6598 was too large, but resize to 8648x3299 succeeded. bundle.min.js line 7141 > eval:201:9
Error: WebGL warning: clear: Requested size 21925x8361 was too large, but resize to 10962x4180 succeeded. bundle.min.js line 15214 > eval:32:60490
Error: WebGL warning: drawingBufferWidth: Requested size 21925x8361 was too large, but resize to 10962x4180 succeeded. bundle.min.js line 7141 > eval:201:9
Error: WebGL warning: clear: Requested size 20379x7772 was too large, but resize to 10189x3886 succeeded. bundle.min.js line 15214 > eval:32:60490
Error: WebGL warning: drawingBufferWidth: Requested size 20379x7772 was too large, but resize to 10189x3886 succeeded. bundle.min.js line 7141 > eval:201:9
Error: WebGL warning: clear: Requested size 18943x7225 was too large, but resize to 9471x3612 succeeded. bundle.min.js line 15214 > eval:32:60490
Error: WebGL warning: drawingBufferWidth: Requested size 18943x7225 was too large, but resize to 9471x3612 succeeded. bundle.min.js line 7141 > eval:201:9
Error: WebGL warning: clear: Requested size 17607x6715 was too large, but resize to 8803x3357 succeeded. bundle.min.js line 15214 > eval:32:60490
Error: WebGL warning: drawingBufferWidth: Requested size 17607x6715 was too large, but resize to 8803x3357 succeeded. bundle.min.js line 7141 > eval:201:9
Error: WebGL warning: clear: Requested size 22314x8510 was too large, but resize to 11157x4255 succeeded. bundle.min.js line 15214 > eval:32:60490
Error: WebGL warning: drawingBufferWidth: Requested size 22314x8510 was too large, but resize to 11157x4255 succeeded. bundle.min.js line 7141 > eval:201:9
Error: WebGL warning: clear: Requested size 20743x7911 was too large, but resize to 10371x3955 succeeded. bundle.min.js line 15214 > eval:32:60490
Error: WebGL warning: drawingBufferWidth: Requested size 20743x7911 was too large, but resize to 10371x3955 succeeded. bundle.min.js line 7141 > eval:201:9
Error: WebGL warning: clear: Requested size 19280x7354 was too large, but resize to 9640x3677 succeeded. bundle.min.js line 15214 > eval:32:60490
Error: WebGL warning: drawingBufferWidth: Requested size 19280x7354 was too large, but resize to 9640x3677 succeeded. bundle.min.js line 7141 > eval:201:9
Error: WebGL warning: clear: Requested size 17925x6834 was too large, but resize to 8962x3417 succeeded. bundle.min.js line 15214 > eval:32:60490
Error: WebGL warning: drawingBufferWidth: Requested size 17925x6834 was too large, but resize to 8962x3417 succeeded. bundle.min.js line 7141 > eval:201:9
Error: WebGL warning: clear: Requested size 16662x6351 was too large, but resize to 8331x3175 succeeded. bundle.min.js line 15214 > eval:32:60490
Error: WebGL warning: drawingBufferWidth: Requested size 16662x6351 was too large, but resize to 8331x3175 succeeded. bundle.min.js line 7141 > eval:201:9
Error: WebGL warning: clear: Requested size 21115x8049 was too large, but resize to 10557x4024 succeeded. bundle.min.js line 15214 > eval:32:60490
Error: WebGL warning: drawingBufferWidth: Requested size 21115x8049 was too large, but resize to 10557x4024 succeeded. bundle.min.js line 7141 > eval:201:9
Error: WebGL warning: clear: Requested size 19626x7482 was too large, but resize to 9813x3741 succeeded. bundle.min.js line 15214 > eval:32:60490
Error: WebGL warning: drawingBufferWidth: Requested size 19626x7482 was too large, but resize to 9813x3741 succeeded. bundle.min.js line 7141 > eval:201:9
Error: WebGL warning: clear: Requested size 18246x6954 was too large, but resize to 9123x3477 succeeded. bundle.min.js line 15214 > eval:32:60490

I took a look at performance with the React profiler:
React Profiler output

In every commit that takes longer to process than normal, it shows AutoSizer taking a long time to render.

Reproducing the problem:

Node version: v10.16.3

  1. Run create-react-app my-app.
  2. Copy code below.
  3. Apply display: none on any element containing the map, including the elements rendered by Deck.gl.

WARNING: Reproducing this issue takes up a lot of resources and might crash your computer!

The code

index.tsx

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import * as serviceWorker from './serviceWorker';
import 'mapbox-gl/dist/mapbox-gl.css';
import {GeoMapChart} from './GeoMapChart'

ReactDOM.render(<GeoMapChart />, document.getElementById('root'));

serviceWorker.unregister();

GeoMapChart.tsx

import * as React from 'react';
import DeckGL from '@deck.gl/react';
import {StaticMap} from 'react-map-gl';


export function GeoMapChart() {

    const [viewState, setViewState] = React.useState(INITIAL_VIEW_STATE);

    return (
            <DeckGL viewState={viewState} controller={true} width={'100%'} height={'100%'} layers={[]}  onViewStateChange={
                ({viewState, oldViewState, interactionState}) => {
                    const newViewState = {...viewState};
                    setViewState(newViewState);
                }}>

                <StaticMap width={'100%'} height={'100%'} mapStyle={MAPBOX_BASE_LAYER}/>
            </DeckGL>
    )
}

const MAX_ZOOM = 19;
const MIN_ZOOM = 2;
const INITIAL_VIEW_STATE = {
    latitude: 37.77,
    longitude: -122.42,
    zoom: 5,
    bearing: 0,
    pitch: 0,
    maxZoom: MAX_ZOOM,
    minZoom: MIN_ZOOM
};


const BASEMAP_TILE_SOURCE_NAME = 'simple-tiles';
const BASEMAP_TILE_SERVERS = [
    'http://a.tile.osm.org/{z}/{x}/{y}.png',
    'http://b.tile.osm.org/{z}/{x}/{y}.png',
    'http://c.tile.osm.org/{z}/{x}/{y}.png',
    //'//stamen-tiles-a.a.ssl.fastly.net/terrain/{z}/{x}/{y}.jpg',
    //'//stamen-tiles-b.a.ssl.fastly.net/terrain/{z}/{x}/{y}.jpg',
    //'//stamen-tiles-c.a.ssl.fastly.net/terrain/{z}/{x}/{y}.jpg',
];
const BASEMAP_ATTRIBUTION = `Map tiles by <a href="http://stamen.com">Stamen Design</a>, under
<a href="http://creativecommons.org/licenses/by/3.0"> CC BY 3.0</a>. Data by
<a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://www.openstreetmap.org/copyright">
ODbL</a>.`.replace(/n/gm, '');
const COMMON_LAYER_CONFIG = {
    minZoom: 2,
    maxZoom: 17, // New data will be requested until this level
    pixelScaleFactor: 8,
    tileSize: 256,
    isTms: true,
    topoLayerClusteringSwithLevel: 13,
    maxVisibleRasterLayers: 3,
    maxConfigurableLayers: 26,
};
const MAP_CONFIG = {
    MIN_ZOOM: 1,
    MAX_ZOOM: 18,
    INITIAL_ZOOM: 9,
    SHOW_TILE_BOUNDARIES: false,
    DRAG_ROTATE: false,
    ZOOM_NO_DATA: 2,
    SEARCH_DEFAULT_ZOOM: 14,
};

const MAPBOX_BASE_LAYER = {
    version: 8,
    sources: {
        [BASEMAP_TILE_SOURCE_NAME]: {
            type: 'raster',
            tiles: BASEMAP_TILE_SERVERS,
            tileSize: COMMON_LAYER_CONFIG.tileSize,
            attribution: BASEMAP_ATTRIBUTION,
        }
    },
    layers: [
        {
            id: BASEMAP_TILE_SOURCE_NAME,
            type: 'raster',
            source: BASEMAP_TILE_SOURCE_NAME,
            minzoom: MAP_CONFIG.MIN_ZOOM,
            maxzoom: MAP_CONFIG.MAX_ZOOM,
        }
    ],
};

index.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />

  <title>Deck.gl performance issue</title>
</head>

<body>
  <div id="root"></div>

</body>

</html>

package.json

{
    "name": "portal_x_dashboard_ui_boot",
    "version": "0.1.0",
    "private": true,
    "dependencies": {
        "@types/lodash": "^4.14.149",
        "@types/node": "13.1.8",
        "@types/react": "16.8.3",
        "@types/react-dom": "16.0.11",
        "@types/react-router-dom": "5.1.3",
        "axios": "0.19.0",
        "deck.gl": "7.3.7",
        "jss": "10.0.0-alpha.3",
        "lodash": "4.17.15",
        "react": "16.8.5",
        "react-dom": "16.8.5",
        "react-map-gl": "5.1.3",
        "react-router-dom": "5.1.2"
    },
    "scripts": {
        "start": "webpack-dev-server --mode development --hot",
        "build": "webpack --mode production",
        "test": "react-scripts test",
        "eject": "react-scripts eject"
    },
    "eslintConfig": {
        "extends": "react-app"
    },
    "browserslist": [
        ">0.2%",
        "not dead",
        "not ie <= 11",
        "not op_mini all"
    ],
    "devDependencies": {
        "@danmarshall/deckgl-typings": "^3.4.3",
        "@types/react-map-gl": "^5.0.3",
        "@types/uuid": "^3.4.6",
        "awesome-typescript-loader": "^5.2.1",
        "babel-jest": "^23.6.0",
        "css-loader": "^2.1.0",
        "enzyme": "^3.8.0",
        "enzyme-adapter-react-16": "^1.7.1",
        "enzyme-to-json": "^3.3.5",
        "html-loader": "^0.5.5",
        "html-webpack-plugin": "^3.2.0",
        "jest": "^23.6.0",
        "node-sass": "^4.11.0",
        "react-scripts": "2.1.2",
        "react-test-renderer": "^16.7.0",
        "sass-loader": "^7.1.0",
        "source-map-loader": "^0.2.4",
        "style-loader": "^0.23.1",
        "typescript": "3.7.4",
        "webpack": "^4.28.1",
        "webpack-cli": "^3.2.1",
        "webpack-dev-server": "^3.1.14"
    },
    "jest": {
        "snapshotSerializers": [
            "enzyme-to-json/serializer"
        ]
    }
}

webpack.config.js

const path = require('path');

const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  entry: './src/index.tsx',
  devServer: {
    port: 9012,
    historyApiFallback: true,
  },
  resolve: {
    extensions: ['.ts', '.tsx', '.js']
  },
  output: {
    path: path.join(__dirname, '/dist'),
    filename: 'bundle.min.js'
  },
  module: {
    rules: [
      {
        test: /.tsx?$/,
        loader: 'awesome-typescript-loader'
      },
      {
        test:/.css$/,
        use:['style-loader','css-loader', 'sass-loader']
      },
      {
        test: /.scss$/, 
        use:["css-loader",'sass-loader']
      },
      {
        test: /.(?:png|jpg|svg)$/,
        loader: 'url-loader'

    },
    {
      test: /.(ico|jpeg|gif|eot|otf|webp|ttf|woff|woff2)(?.*)?$/,
      loader: 'file-loader'

  },
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: '!!html-loader!./src/index.html'
    }),

  ]
}

tsconfig.json

{
    "compilerOptions": {
        "outDir": "./dist/",
        "sourceMap": true,
        "noImplicitAny": false,
        "module": "commonjs",
        "target": "es6",
        "jsx": "react",
        // "suppressImplicitAnyIndexErrors": true,
    },
    "include": [
        "./src/**/*"
    ]
}


Get this bounty!!!

#StackBounty: #unity #c# #webgl #assetbundle WebGL Freeze for some minutes after loading asset bundle

Bounty: 50

I have to Load/Unload models from a specific URL based on player position. For this reason I am checking player position from model and then load/unload related piece of model in a Update event which runs on every frame.

Here is the update, that validating some checks before loading/unloading. I added this check for optimization purposes as the main loading/unloading loop is heavy:

 private void Update()
    {
        //If this feature is disable don't load/unload
        if (enableThisFeature == false) return;

        //if player is moving, dont load//unload
        if (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0)
        {
            //do nothing when player is moving
            return;
        }

        DeactivateDistantTiles();
    }

After this I am checking player position and calling model load/unload:

private void DeactivateDistantTiles()
    {
        playerPosition = transform.position;
        playerPosition = cameraController.currentActiveCam.transform.position; //transform.position;

        checkPlayerPositionChangeing = playerPosition.z != playerLastPos.z || playerPosition.x != playerLastPos.x;

        if (checkPlayerPositionChangeing)
        {
            ABLoadUnloadLoopCall();
        }


        playerLastPos = cameraController.currentActiveCam.transform.position;

    }
    Vector3 tilePosition;
    float xDistance;
    float zDistance;
    public void ABLoadUnloadLoopCall()
    {

          //old
            //foreach (SingleABLoader tile in tiles)
            //{
            //    Debug.Log("ABLoadUnloadLoopCall 123");
            //    Vector3 tilePosition = tile.gameObject.transform.position + (tileSize / 2f);

            //    float xDistance = Mathf.Abs(tilePosition.x - playerPosition.x);
            //    float zDistance = Mathf.Abs(tilePosition.z - playerPosition.z);

            //    if (xDistance + zDistance > maxDistance)
            //    {
            //        /*If you don't want to destroy the object on unload then use below line otherwise use DestroyBundleObject with true pararmeter */
            //        //tile.DestroyBundleObject();
            //        tile.DestroyBundleObject(true);
            //    }
            //    else
            //    {
            //        tile.StartDownloadingAB();
            //    }

            //}
            //new
            for(int i = 0; i < tiles.Length; i++)
            {

                tilePosition = tiles[i].gameObject.transform.position + (tileSize / 2f);

                 xDistance = Mathf.Abs(tilePosition.x - playerPosition.x);
                 zDistance = Mathf.Abs(tilePosition.z - playerPosition.z);

                if (xDistance + zDistance > maxDistance)
                {

                    /*If you don't want to destroy the object on unload then use below line otherwise use DestroyBundleObject with true pararmeter */
                    //tiles[i].DestroyBundleObject();
                    tiles[i].DestroyBundleObject(true);

                }
                else
                {
                    tiles[i].StartDownloadingAB();
                }

            }


    }

I found that ABLoadUnloadLoopCall making GC allocation in KBs in every frame which is very high (i think this is a problem, maybe i am wrong). So is there any way available that my above code optimize and make less allocation. My initial research suggest to use For loop instead foreach therefore in ABLoadUnloadLoopCall I am using for loop instead foreach but still my game lag/freeze for some minutes after loading the model/asset bundle. The lag/jerky/freeze usually disappear after some minutes/seconds of asset bundle loading.

Edit:
Some More Code Snippet Added.
Here is the Bundle/Model loading Code. Whenever a asset bundle download is require it add the download in a queue which later process one by one.

public void StartDownloadingAB()
    {
        if (BundleLoadStatus == BundleLoadStatusEnum.bundleNotLoadedYet)
        {
            BundleLoadStatus = BundleLoadStatusEnum.bundlesLoading;
            enqueTheABDownloading.EnqueABDownloading(this);
        }

    }
//actual code the download the bundle.
    public IEnumerator DownloadAB()
        {

            if (isBundleLoading == true)
                yield return false;

            BundleLoadStatus = BundleLoadStatusEnum.bundlesLoading;
            isBundleLoading = true;

            www = UnityWebRequestAssetBundle.GetAssetBundle(finalABLoaderURL);
            yield return www.SendWebRequest();

            if (www.error != null)
            {
                Debug.LogError("assetBundleURL : " + finalABLoaderURL);
                Debug.LogError("www error : " + www.error);
                www.Dispose();
                www = null;
                yield break;
            }

            bundle = ((DownloadHandlerAssetBundle)www.downloadHandler).assetBundle;

            AssetBundleRequest bundlePrefabAsync = bundle.LoadAssetAsync(bundle.name, typeof(GameObject));
            yield return bundlePrefabAsync;

            // if we got something out
            if (bundlePrefabAsync != null)
            {
                //First Off the Origin S***fting
                environmentOriginSetter.EnvironmentOriginSetterFeatureActive(false);//TODO
                //assetBundleToLoadObj = (GameObject)Instantiate(bundlePrefab);

                //Then Instantiate the Bundel Object and make it child to environment parent object.
                assetBundleToLoadObj = Instantiate(bundlePrefabAsync.asset as GameObject);
                assetBundleToLoadObj.transform.parent = envParent.transform;
                //assetBundleToLoadObj.transform.parent.transform.position = this.transform.localPosition;//new

                //Then Enable the Origin Setter feature again
                environmentOriginSetter.EnvironmentOriginSetterFeatureActive(true);


            }

            www.Dispose();
            www = null;

            // try to cleanup memory
            //Resources.UnloadUnusedAssets();//TODO open if memory problem occur
            bundle.Unload(false);//TODO open if memory problem occur
            bundle = null;

            isBundleLoading = false;
            BundleLoadStatus = BundleLoadStatusEnum.bundlesHasLoaded;
        }

For Unloading, I am destroying the object

 public void DestroyBundleObject(bool isDestroy)
    {
        //bundle was loaded completely, write a bool, if it is true then loaded completely
        //bundle is loading, isBundleLoading
        //bundle is not load yet, 

        if (bundleObjectsDeleted == false && BundleLoadStatus == BundleLoadStatusEnum.bundlesHasLoaded)
        {
            bundleObjectsDeleted = true;
            if (assetBundleToLoadObj)
            {
                Destroy(assetBundleToLoadObj);
            }               
            BundleLoadStatus = BundleLoadStatusEnum.bundleNotLoadedYet;
        }

    }

Before loading the bundle/Model, I Enque the desired bundle in a list and download it one by one.

public void EnqueABDownloading(SingleABLoader abToDownload)
{

    if (!singleAbLoader.Contains(abToDownload))
    {
        Debug.Log("Enque " + abToDownload.gameObject.name);
        singleAbLoader.Enqueue(abToDownload);

        if (isDownloadStarted == false)
        {
            StartCoroutine(StartDownloading());
        }
    }

}

public IEnumerator StartDownloading()
{

isDownloadStarted = true;
Application.runInBackground = true;//enforce background loading.
imgBlockClicks.SetActive(true);
textLoading.SetActive(true);
loadingSlider.gameObject.SetActive(true);

while (singleAbLoader.Count > 0)
{
    float sliderIncrementValue = 1f / singleAbLoader.Count;

    SingleABLoader singleAbLoaderCurrent = singleAbLoader.Dequeue();
    Debug.Log("Starting to call " + singleAbLoaderCurrent.gameObject.name);
    yield return singleAbLoaderCurrent.DownloadAB();
    Debug.Log("Finsihed to call " + singleAbLoaderCurrent.gameObject.name);
    //Debug.Log("Finished next loop");
    //singleAbLoaderCurrent.CallDownloadAB();
    //Debug.Log("download call for "+ singleAbLoaderCurrent.name);
    loadingSlider.value = sliderIncrementValue;
}

isDownloadStarted = false;

textLoading.SetActive(false);
imgBlockClicks.SetActive(false);

//Application.runInBackground = false;
loadingSlider.gameObject.SetActive(false);
loadingSlider.value = 0;

}

I tried to profile on editor and found something like this:
enter image description here

My recent test suggest that the error is occuring in FireFox and chrome while Edge is running fine.


Get this bounty!!!

#StackBounty: #unity #webgl Why WebGL Audio isn't working?

Bounty: 100

I need to download audio (OGG, Mp3 or wav) from URL and play it.

In Editor is working fine, and also in stand alone build.

But not in WebGL build.

My Code:

    // Here audio is downloaded based on audioURL
...
      WWW data = new WWW(audioURL); yield return data;
            AudioClip downloadedClip = data.GetAudioClipCompressed(false, AudioType.OGGVORBIS) as AudioClip;
            if (downloadedClip != null)
            {
                _audio.clip = downloadedClip;
            }
...


public void PlayAudio() {
    // Here clip is play
            if (_audio.clip != null && _audio.isPlaying == false)
                _audio.Play();
            else
                Debug.Log("Background music not present!");
            _audio.loop = true;
}

To download clip i’ve used also (instead first code part):

 using (UnityWebRequest www2 = UnityWebRequestMultimedia.GetAudioClip(audioURL, AudioType.OGGVORBIS))
        {
            yield return www2.SendWebRequest();

            if (www2.isHttpError)
            {
                Debug.Log(www2.error);
                LogAdd(www.error, true);
            }
            else
            {
                AudioClip downloadedClip = DownloadHandlerAudioClip.GetContent(www2);                
                _audio.clip = downloadedClip;
            }
        }

For some reason, audio in webgl isn’t played.

EDIT 1: When uploading MP3 , error (also in editor) is:

Streaming of ‘mpeg’ on this platform is not supported
UnityEngine.Networking.DownloadHandlerAudioClip:GetContent(UnityWebRequest)


Get this bounty!!!

#StackBounty: #unity #webgl Why WebGL Audio isn't working?

Bounty: 100

I need to download audio (OGG, Mp3 or wav) from URL and play it.

In Editor is working fine, and also in stand alone build.

But not in WebGL build.

My Code:

    // Here audio is downloaded based on audioURL
...
      WWW data = new WWW(audioURL); yield return data;
            AudioClip downloadedClip = data.GetAudioClipCompressed(false, AudioType.OGGVORBIS) as AudioClip;
            if (downloadedClip != null)
            {
                _audio.clip = downloadedClip;
            }
...


public void PlayAudio() {
    // Here clip is play
            if (_audio.clip != null && _audio.isPlaying == false)
                _audio.Play();
            else
                Debug.Log("Background music not present!");
            _audio.loop = true;
}

To download clip i’ve used also (instead first code part):

 using (UnityWebRequest www2 = UnityWebRequestMultimedia.GetAudioClip(audioURL, AudioType.OGGVORBIS))
        {
            yield return www2.SendWebRequest();

            if (www2.isHttpError)
            {
                Debug.Log(www2.error);
                LogAdd(www.error, true);
            }
            else
            {
                AudioClip downloadedClip = DownloadHandlerAudioClip.GetContent(www2);                
                _audio.clip = downloadedClip;
            }
        }

For some reason, audio in webgl isn’t played.

EDIT 1: When uploading MP3 , error (also in editor) is:

Streaming of ‘mpeg’ on this platform is not supported
UnityEngine.Networking.DownloadHandlerAudioClip:GetContent(UnityWebRequest)


Get this bounty!!!

#StackBounty: #unity #webgl Why WebGL Audio isn't working?

Bounty: 100

I need to download audio (OGG, Mp3 or wav) from URL and play it.

In Editor is working fine, and also in stand alone build.

But not in WebGL build.

My Code:

    // Here audio is downloaded based on audioURL
...
      WWW data = new WWW(audioURL); yield return data;
            AudioClip downloadedClip = data.GetAudioClipCompressed(false, AudioType.OGGVORBIS) as AudioClip;
            if (downloadedClip != null)
            {
                _audio.clip = downloadedClip;
            }
...


public void PlayAudio() {
    // Here clip is play
            if (_audio.clip != null && _audio.isPlaying == false)
                _audio.Play();
            else
                Debug.Log("Background music not present!");
            _audio.loop = true;
}

To download clip i’ve used also (instead first code part):

 using (UnityWebRequest www2 = UnityWebRequestMultimedia.GetAudioClip(audioURL, AudioType.OGGVORBIS))
        {
            yield return www2.SendWebRequest();

            if (www2.isHttpError)
            {
                Debug.Log(www2.error);
                LogAdd(www.error, true);
            }
            else
            {
                AudioClip downloadedClip = DownloadHandlerAudioClip.GetContent(www2);                
                _audio.clip = downloadedClip;
            }
        }

For some reason, audio in webgl isn’t played.

EDIT 1: When uploading MP3 , error (also in editor) is:

Streaming of ‘mpeg’ on this platform is not supported
UnityEngine.Networking.DownloadHandlerAudioClip:GetContent(UnityWebRequest)


Get this bounty!!!

#StackBounty: #unity #webgl Why WebGL Audio isn't working?

Bounty: 100

I need to download audio (OGG, Mp3 or wav) from URL and play it.

In Editor is working fine, and also in stand alone build.

But not in WebGL build.

My Code:

    // Here audio is downloaded based on audioURL
...
      WWW data = new WWW(audioURL); yield return data;
            AudioClip downloadedClip = data.GetAudioClipCompressed(false, AudioType.OGGVORBIS) as AudioClip;
            if (downloadedClip != null)
            {
                _audio.clip = downloadedClip;
            }
...


public void PlayAudio() {
    // Here clip is play
            if (_audio.clip != null && _audio.isPlaying == false)
                _audio.Play();
            else
                Debug.Log("Background music not present!");
            _audio.loop = true;
}

To download clip i’ve used also (instead first code part):

 using (UnityWebRequest www2 = UnityWebRequestMultimedia.GetAudioClip(audioURL, AudioType.OGGVORBIS))
        {
            yield return www2.SendWebRequest();

            if (www2.isHttpError)
            {
                Debug.Log(www2.error);
                LogAdd(www.error, true);
            }
            else
            {
                AudioClip downloadedClip = DownloadHandlerAudioClip.GetContent(www2);                
                _audio.clip = downloadedClip;
            }
        }

For some reason, audio in webgl isn’t played.

EDIT 1: When uploading MP3 , error (also in editor) is:

Streaming of ‘mpeg’ on this platform is not supported
UnityEngine.Networking.DownloadHandlerAudioClip:GetContent(UnityWebRequest)


Get this bounty!!!

#StackBounty: #unity #webgl Why WebGL Audio isn't working?

Bounty: 100

I need to download audio (OGG, Mp3 or wav) from URL and play it.

In Editor is working fine, and also in stand alone build.

But not in WebGL build.

My Code:

    // Here audio is downloaded based on audioURL
...
      WWW data = new WWW(audioURL); yield return data;
            AudioClip downloadedClip = data.GetAudioClipCompressed(false, AudioType.OGGVORBIS) as AudioClip;
            if (downloadedClip != null)
            {
                _audio.clip = downloadedClip;
            }
...


public void PlayAudio() {
    // Here clip is play
            if (_audio.clip != null && _audio.isPlaying == false)
                _audio.Play();
            else
                Debug.Log("Background music not present!");
            _audio.loop = true;
}

To download clip i’ve used also (instead first code part):

 using (UnityWebRequest www2 = UnityWebRequestMultimedia.GetAudioClip(audioURL, AudioType.OGGVORBIS))
        {
            yield return www2.SendWebRequest();

            if (www2.isHttpError)
            {
                Debug.Log(www2.error);
                LogAdd(www.error, true);
            }
            else
            {
                AudioClip downloadedClip = DownloadHandlerAudioClip.GetContent(www2);                
                _audio.clip = downloadedClip;
            }
        }

For some reason, audio in webgl isn’t played.

EDIT 1: When uploading MP3 , error (also in editor) is:

Streaming of ‘mpeg’ on this platform is not supported
UnityEngine.Networking.DownloadHandlerAudioClip:GetContent(UnityWebRequest)


Get this bounty!!!

#StackBounty: #unity #webgl Why WebGL Audio isn't working?

Bounty: 100

I need to download audio (OGG, Mp3 or wav) from URL and play it.

In Editor is working fine, and also in stand alone build.

But not in WebGL build.

My Code:

    // Here audio is downloaded based on audioURL
...
      WWW data = new WWW(audioURL); yield return data;
            AudioClip downloadedClip = data.GetAudioClipCompressed(false, AudioType.OGGVORBIS) as AudioClip;
            if (downloadedClip != null)
            {
                _audio.clip = downloadedClip;
            }
...


public void PlayAudio() {
    // Here clip is play
            if (_audio.clip != null && _audio.isPlaying == false)
                _audio.Play();
            else
                Debug.Log("Background music not present!");
            _audio.loop = true;
}

To download clip i’ve used also (instead first code part):

 using (UnityWebRequest www2 = UnityWebRequestMultimedia.GetAudioClip(audioURL, AudioType.OGGVORBIS))
        {
            yield return www2.SendWebRequest();

            if (www2.isHttpError)
            {
                Debug.Log(www2.error);
                LogAdd(www.error, true);
            }
            else
            {
                AudioClip downloadedClip = DownloadHandlerAudioClip.GetContent(www2);                
                _audio.clip = downloadedClip;
            }
        }

For some reason, audio in webgl isn’t played.

EDIT 1: When uploading MP3 , error (also in editor) is:

Streaming of ‘mpeg’ on this platform is not supported
UnityEngine.Networking.DownloadHandlerAudioClip:GetContent(UnityWebRequest)


Get this bounty!!!

#StackBounty: #unity #webgl Why WebGL Audio isn't working?

Bounty: 100

I need to download audio (OGG, Mp3 or wav) from URL and play it.

In Editor is working fine, and also in stand alone build.

But not in WebGL build.

My Code:

    // Here audio is downloaded based on audioURL
...
      WWW data = new WWW(audioURL); yield return data;
            AudioClip downloadedClip = data.GetAudioClipCompressed(false, AudioType.OGGVORBIS) as AudioClip;
            if (downloadedClip != null)
            {
                _audio.clip = downloadedClip;
            }
...


public void PlayAudio() {
    // Here clip is play
            if (_audio.clip != null && _audio.isPlaying == false)
                _audio.Play();
            else
                Debug.Log("Background music not present!");
            _audio.loop = true;
}

To download clip i’ve used also (instead first code part):

 using (UnityWebRequest www2 = UnityWebRequestMultimedia.GetAudioClip(audioURL, AudioType.OGGVORBIS))
        {
            yield return www2.SendWebRequest();

            if (www2.isHttpError)
            {
                Debug.Log(www2.error);
                LogAdd(www.error, true);
            }
            else
            {
                AudioClip downloadedClip = DownloadHandlerAudioClip.GetContent(www2);                
                _audio.clip = downloadedClip;
            }
        }

For some reason, audio in webgl isn’t played.

EDIT 1: When uploading MP3 , error (also in editor) is:

Streaming of ‘mpeg’ on this platform is not supported
UnityEngine.Networking.DownloadHandlerAudioClip:GetContent(UnityWebRequest)


Get this bounty!!!