YouTube 播放器无法构建,不断出现错误。

huangapple go评论68阅读模式
英文:

YouTube player cannot be built and keeps throwing error

问题

我正在尝试在我的React Native TypeScript移动应用中使用YouTube播放器package,但它抛出了一个错误,我无法弄清楚如何解决这个问题。我已经进行了大量研究并安装了一些包,如deprecated-react-native-prop-typesmetro-react-native-babel-preset,但仍然没有运气。

在Google Cloud平台上,我已经在我的项目中启用了YouTube嵌入式播放器API产品,并在其中创建了一个API密钥。

我在Android Studio模拟器上本地运行我的应用程序,并使用了所有最新的包。这是否与此有关?

我的代码:

<YouTube
    apiKey="API密钥在此"
    videoId="KVZ-P-ZI6W4"
    play={true}
    fullscreen={false}
    loop={false}
    onReady={(e): void => { console.log(e); }}
    onChangeState={(): void => { console.log(); }}
    onChangeQuality={(): void => { console.log(); }}
    onError={(e): void => { console.log(e); }}
    style={{ alignSelf: 'stretch', height: 300 }}
/>

onError返回的错误对象:

{"error": "SERVICE_MISSING", "target": 235}

错误弹出窗口:

获取YouTube应用程序:

此应用程序无法运行,因为您的设备缺少YouTube应用程序。
英文:

I'm trying to use the YouTube player package in my React Native TypeScript mobile app but it's throwing an error and I cannot figure out how to fix this issue. I have researched a lot and installed some packages such as deprecated-react-native-prop-types and metro-react-native-babel-preset but still no luck.

In the Google Cloud Platform, I have enabled the YouTube Embedded Player API product in my project and created an API Key in it.

I'm running my application locally on the Android Studio Emulator and is using all the latest packages. Would that have anything to do with it?

My Code:

&lt;YouTube
	apiKey = &quot;API KEY HERE&quot;
	videoId = &quot;KVZ-P-ZI6W4&quot;
	play = {true}
	fullscreen = {false}
	loop = {false}
	onReady={(e): void =&gt; { console.log(e); }}
	onChangeState={(): void =&gt; { console.log(); }}
	onChangeQuality={(): void =&gt; { console.log(); }}
	onError={(e): void =&gt; { console.log(e); }}
	style={{ alignSelf: &#39;stretch&#39;, height: 300 }}
/&gt;

Error object return on onError:

{&quot;error&quot;: &quot;SERVICE_MISSING&quot;, &quot;target&quot;: 235}

Error popup:

Get YouTube app:

This app won&#39;t run without the YouTube App, which is missing from your device.

答案1

得分: 0

对于Android,我不得不将以下代码添加到AndroidManifest.xml中。至于iOS,在我的iPhone 6s Plus设备上,目前没有任何特殊更改。

<queries>
    <intent>
        <action android:name="com.google.android.youtube.api.service.START" />
    </intent>
</queries>

其他信息:

Android设备:Pixel 5 - API 31
react-native0.71.8
react-native-youtube^2.0.2
typescript^5.0.4

英文:

For Android, I had to add the following code to the AndroidManifest.xml. For IOS, so far it's working on my iPhone 6s Plus device without any special change.

&lt;queries&gt;
	&lt;intent&gt;
		&lt;action android:name=&quot;com.google.android.youtube.api.service.START&quot; /&gt;
	&lt;/intent&gt;
&lt;/queries&gt;

Other information:

Android Device: Pixel 5 - API 31
react-native: 0.71.8
react-native-youtube: ^2.0.2
typescript: ^5.0.4

huangapple
  • 本文由 发表于 2023年1月9日 17:53:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/75055565.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定