我正在努力记录用户的麦克风输入并对其进行处理。问题是我正在使用 scriptProcessorNode 来处理数据,但这里说它已被弃用并替换为AudioWorklet。问题是没有明确的方法可以用 AudioWorklet 替换此功能,并且从所有示例项目中都可以看到来自 Google 的AudioWorklets,它们都没有对麦克风输入执行任何操作。有没有办法用 Audio Worklet 替换此代码?这是“应该”替换的代码。
// Connect analyser
this.options.source.connect(this.analyser);
// Create ScriptProcessorNode
this.scriptProcessorNode = this.options.context.createScriptProcessor(this.options.bufferLen, numChannels, numChannels);
// Connect scriptProcessorNode (Theretically, not required)
this.scriptProcessorNode.connect(this.options.context.destination);
// Create callback to update/analyze floatFrequencyData
var self = this;
this.scriptProcessorNode.onaudioprocess = function (event) {
self.analyser.getFloatFrequencyData(self.floatFrequencyData);
self.update();
self.store(event);
self.monitor();
};
// Connect scriptProcessorNode
this.options.source.connect(this.scriptProcessorNode);
Run Code Online (Sandbox Code Playgroud) 我正在使用LitElement创建自定义Web组件。我对此很陌生,因此决定尝试制作图像幻灯片。我 在修改W3Schools幻灯片以使其可用作LitElement时将其用作参考。问题是,当我尝试使用document.getElementByClassName时,我什么也没得到。由于我正在使用Shadow DOM,因此我对这个问题很熟悉,因此我将其更改为this.shadowRoot.getElementsByClassName。不幸的是,我被告知我要使用的不是函数。使用LitElement和shadow dom时如何按类名获取元素?如果您想查看我的组件的外观,下面是代码:
import { LitElement, html} from '@polymer/lit-element';
class ImageGalleryElement extends LitElement {
static get properties() { return {
slideIndex: { type: Number },
}};
constructor(){
super();
this.slideIndex=1;
this.showSlides(this.slideIndex);
}
// Next/previous controls
plusSlides(n) {
this.showSlides(this.slideIndex += n);
}
// Thumbnail image controls
currentSlide(n) {
this.showSlides(this.slideIndex = n);
}
showSlides(n) {
var i;
console.dir(this.shadowRoot);
var slides = this.shadowRoot.getElementsByClassName("mySlides");
console.dir(slides);
var dots = this.shadowRoot.getElementsByClassName("dot");
if (n > slides.length) {this.slideIndex = 1}
if (n < 1) …Run Code Online (Sandbox Code Playgroud) 我们正在使用 Lit Element 并且我们的组件文件变得相当大,因为我们必须在 .js 文件中编写样式和 html。有没有办法将它们拆分成单独的文件,然后将它们导入到我们的组件中?这样做的最佳方法是什么?HTML 和 CSS 尤其让我们的工作流程变得困难,因为我们的文件变得过于臃肿。
更新:Supersharp 的建议帮助我分离了 CSS 和 html 模板,但我在将 html 模板与指定属性绑定时遇到了问题。我有一个服务文件,它为我指定的文件发出 XML 请求,我将它导入到我的组件文件中。这是我的组件:
import { LitElement, html} from '@polymer/lit-element';
import HtmlLoader from './Service/HtmlLoader';
class TestAnimatedButtonElement extends LitElement {
static get properties() {
return {
_text: {
type: String
}
}
}
constructor() {
super();
this.htmlTemplate = HtmlLoader.prototype.getHtmlTemplate('/src/Components/ExampleElements/test-animated-button-element.html');
}
render(){
this.htmlTemplate.then( template => this.shadowRoot.innerHTML = template)
return html( [this.htmlTemplate] );
}
handleButton(e) {
//e.preventDefault();
console.log('Button pressed');
}
}
customElements.define('test-animated-button-element', TestAnimatedButtonElement);
Run Code Online (Sandbox Code Playgroud)
这是我的 html 文件: …
我正在尝试使用 NetTopologySuite 计算两点之间的距离。由于我引用了 Microsoft 文档,因此我想出了以下 GeometryExtension 和 GeometryHelper 类:
public static class GeometryExtensions
{
private static readonly CoordinateSystemServices _coordinateSystemServices = new CoordinateSystemServices(new Dictionary<int, string>
{
// Coordinate systems:
[4326] = GeographicCoordinateSystem.WGS84.WKT,
// CRS for Denmark ESPG 25832. Source: https://epsg.io/25832 and https://sdfe.dk/
[25832] = @"PROJCS[""ETRS89 / UTM zone 32N"",
GEOGCS[""ETRS89"",
DATUM[""European_Terrestrial_Reference_System_1989"",
SPHEROID[""GRS 1980"",6378137,298.257222101,
AUTHORITY[""EPSG"",""7019""]],
TOWGS84[0,0,0,0,0,0,0],
AUTHORITY[""EPSG"",""6258""]],
PRIMEM[""Greenwich"",0,
AUTHORITY[""EPSG"",""8901""]],
UNIT[""degree"",0.0174532925199433,
AUTHORITY[""EPSG"",""9122""]],
AUTHORITY[""EPSG"",""4258""]],
PROJECTION[""Transverse_Mercator""],
PARAMETER[""latitude_of_origin"",0],
PARAMETER[""central_meridian"",9],
PARAMETER[""scale_factor"",0.9996],
PARAMETER[""false_easting"",500000],
PARAMETER[""false_northing"",0],
UNIT[""metre"",1,
AUTHORITY[""EPSG"",""9001""]],
AXIS[""Easting"",EAST],
AXIS[""Northing"",NORTH],
AUTHORITY[""EPSG"",""25832""]]"
}
);
/// <summary>
/// Projects a geometry to …Run Code Online (Sandbox Code Playgroud) .net ×1
.net-core ×1
c# ×1
gis ×1
import ×1
javascript ×1
lit-element ×1
lit-html ×1
module ×1
shadow-dom ×1