英文:
YouTube player cannot be built and keeps throwing error
问题
我正在尝试在我的React Native TypeScript移动应用中使用YouTube
播放器package,但它抛出了一个错误,我无法弄清楚如何解决这个问题。我已经进行了大量研究并安装了一些包,如deprecated-react-native-prop-types
和metro-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:
<YouTube
apiKey = "API KEY HERE"
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 }}
/>
Error object return on onError
:
{"error": "SERVICE_MISSING", "target": 235}
Error popup:
Get YouTube app:
This app won'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-native
:0.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.
<queries>
<intent>
<action android:name="com.google.android.youtube.api.service.START" />
</intent>
</queries>
Other information:
Android Device: Pixel 5 - API 31
react-native
: 0.71.8
react-native-youtube
: ^2.0.2
typescript
: ^5.0.4
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论