简体   繁体   English

音频流的 PhoneGap Android 权限问题

[英]PhoneGap Android permission issue for audio streaming

Almost finished my app with phonegap I did developed the app on iOS and I now need to export and generate apk for Android几乎用phonegap完成了我的应用程序我确实在iOS上开发了该应用程序,现在我需要为Android导出并生成apk

Is v2 app of a couple of year old app I'm using adobe phonegap build to generate the apk是几年前的应用程序的 v2 应用程序我正在使用 adobe phonegap build 来生成 apk

Older app work fine, when I download and install from play store it ask me if a grant "photo/multimedia elements/file" permission较旧的应用程序工作正常,当我从 Play 商店下载并安装时,它会询问我是否授予“照片/多媒体元素/文件”权限

and if I hit the play button streaming starts correctly, on new app it won't play the audio stream and when i install the app from dropbox it won't stream the audio如果我点击播放按钮流媒体正确开始,在新应用程序上它不会播放音频流,当我从保管箱安装应用程序时它不会流媒体音频

I'm using a OnePlus 6t as a test device我使用 OnePlus 6t 作为测试设备

to start audio stream I use this code ( ad I did in previous version )开始音频流我使用这个代码(我在以前的版本中做的广告)

myaudio = new Audio('http://mystream.net:1935/live/myapp.stream/playlist.m3u8');
myaudio.id = 'playerMyAdio';
myaudio.play()

I try to add我尝试添加

<preference name="android.permission.INTERNET" value="none" />
<preference name="android.permission.MEDIA_CONTENT_CONTROL" value="none" />

as found in other question but it doesn't work正如在其他问题中发现的那样,但它不起作用

phonegap -v returns 8.2.2 phonegap -v 返回 8.2.2

this is my config.xml, I guess is a permission issue这是我的 config.xml,我猜是权限问题

<?xml version='1.0' encoding='utf-8'?>
<widget id="it.myapp.app" version="2.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
    <name>myapp</name>
    <description>
        myapp
    </description>
    <author email="info@myapp.com" href="http://www.myapp.com">
        MyAPP
    </author>
    <content src="index.html" />
    <preference name="Orientation" value="portrait" />
    <preference name="DisallowOverscroll" value="true" />
    <preference name="android-minSdkVersion" value="19" />
    <preference name="BackupWebStorage" value="none" />
    <preference name="SplashScreen" value="splash" />
    <preference name="SplashScreenDelay" value="100" />
    <preference name="AutoHideSplashScreen" value="true" />
    <preference name="StatusBarStyle" value="lightcontent" />
    <platform name="android">
        <preference name="ShowSplashScreenSpinner" value="false" />
        <preference name="android.permission.INTERNET" value="none" />
        <preference name="android.permission.MEDIA_CONTENT_CONTROL" value="none" />
    </platform>
    <platform name="android">
        <icon qualifier="ldpi" src="res/icons/android/icon-36-ldpi.png" />
        <icon qualifier="mdpi" src="res/icons/android/icon-48-mdpi.png" />
        <icon qualifier="hdpi" src="res/icons/android/icon-72-hdpi.png" />
        <icon qualifier="xhdpi" src="res/icons/android/icon-96-xhdpi.png" />
        <icon qualifier="xxhdpi" src="res/icons/android/icon-144-xxhdpi.png" />
        <icon qualifier="xxxhdpi" src="res/icons/android/icon-192-xxxhdpi.png" />
        <splash qualifier="ldpi" src="res/screens/android/screen-ldpi-portrait.png" />
        <splash qualifier="mdpi" src="res/screens/android/screen-mdpi-portrait.png" />
        <splash qualifier="hdpi" src="res/screens/android/screen-hdpi-portrait.png" />
        <splash qualifier="xhdpi" src="res/screens/android/screen-xhdpi-portrait.png" />
    </platform>
    <platform name="ios">
        <icon height="20" platform="ios" src="res/icons/ios/icon-20.png" width="20" />
        <icon height="40" platform="ios" src="res/icons/ios/icon-20@2x.png" width="40" />
        <icon height="60" platform="ios" src="res/icons/ios/icon-20@3x.png" width="60" />
        <icon height="29" platform="ios" src="res/icons/ios/icon-29.png" width="29" />
        <icon height="58" platform="ios" src="res/icons/ios/icon-29@2x.png" width="58" />
        <icon height="87" platform="ios" src="res/icons/ios/icon-29@3x.png" width="87" />
        <icon height="80" platform="ios" src="res/icons/ios/icon-40@2x.png" width="80" />
        <icon height="120" platform="ios" src="res/icons/ios/icon-40@3x.png" width="120" />
        <icon height="50" platform="ios" src="res/icons/ios/icon-50.png" width="50" />
        <icon height="100" platform="ios" src="res/icons/ios/icon-50@2x.png" width="100" />
        <icon height="57" platform="ios" src="res/icons/ios/icon-57.png" width="57" />
        <icon height="114" platform="ios" src="res/icons/ios/icon-57@2x.png" width="114" />
        <icon height="180" platform="ios" src="res/icons/ios/icon-60@3x.png" width="180" />
        <icon height="72" platform="ios" src="res/icons/ios/icon-72.png" width="72" />
        <icon height="144" platform="ios" src="res/icons/ios/icon-72@2x.png" width="144" />
        <icon height="76" platform="ios" src="res/icons/ios/icon-76.png" width="76" />
        <icon height="152" platform="ios" src="res/icons/ios/icon-76@2x.png" width="152" />
        <icon height="167" platform="ios" src="res/icons/ios/icon-83.5@2x.png" width="167" />
        <icon height="1024" platform="ios" src="res/icons/ios/icon-1024.png" width="1024" />
        <splash height="480" platform="ios" src="res/screens/ios/screen-iphone-portrait.png" width="320" />
        <splash height="960" platform="ios" src="res/screens/ios/screen-iphone-portrait-2x.png" width="640" />
        <splash height="1136" platform="ios" src="res/screens/ios/screen-iphone-portrait-568h-2x.png" width="640" />
        <splash height="1334" platform="ios" src="res/screens/ios/screen-iphone-portrait-667h.png" width="750" />
        <splash height="2208" platform="ios" src="res/screens/ios/screen-iphone-portrait-736h.png" width="1242" />
        <splash height="1024" platform="ios" src="res/screens/ios/screen-ipad-portrait.png" width="768" />
        <splash height="2048" platform="ios" src="res/screens/ios/screen-ipad-portrait-2x.png" width="1536" />
        <splash height="320" platform="ios" src="res/screens/ios/screen-iphone-landscape.png" width="480" />
        <splash height="640" platform="ios" src="res/screens/ios/screen-iphone-landscape-2x.png" width="960" />
        <splash height="640" platform="ios" src="res/screens/ios/screen-iphone-landscape-568h-2x.png" width="1136" />
        <splash height="750" platform="ios" src="res/screens/ios/screen-iphone-landscape-667h.png" width="1334" />
        <splash height="1242" platform="ios" src="res/screens/ios/screen-iphone-landscape-736h.png" width="2208" />
        <splash height="768" platform="ios" src="res/screens/ios/screen-ipad-landscape.png" width="1024" />
        <splash height="1536" platform="ios" src="res/screens/ios/screen-ipad-landscape-2x.png" width="2048" />
        <splash height="2732" platform="ios" src="res/screens/ios/Default@2x~universal~anyany.png" width="2732" />
    </platform>
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
        <allow-intent href="market:*" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
    <plugin name="cordova-plugin-whitelist" spec="^1.3.3" />
    <plugin name="cordova-plugin-x-socialsharing" source="npm" version="5.4.0" />
    <plugin name="nl.kingsquare.cordova.background-audio" spec="^1.0.1" />
    <plugin name="cordova-plugin-splashscreen" spec="^5.0.2" />
    <plugin name="cordova-plugin-statusbar" spec="^2.4.2" />
    <engine name="browser" spec="^5.0.4" />
    <engine name="ios" spec="^4.5.5" />
    <engine name="android" spec="~7.1.4" />
</widget>

the OnePlus 6T seems to run a current version of Android OS, which by default restricts HTTP traffic. OnePlus 6T 似乎运行当前版本的 Android 操作系统,默认情况下会限制HTTP流量。

for Cordova, you need to reference a network_security_config.xml alike this:对于 Cordova,您需要像这样引用network_security_config.xml

<platform name="android">
    <edit-config xmlns:android="http://schemas.android.com/apk/res/android" file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
        <application android:networkSecurityConfig="@xml/network_security_config" />
    </edit-config>
    <resource-file src="network_security_config.xml" target="app/src/main/res/xml/network_security_config.xml" />
</platform>

where the network_security_config.xml would require this one exclusion:其中network_security_config.xml将需要此排除项:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain>mystream.net</domain>
    </domain-config>
</network-security-config>

According to Android Documentation MEDIA_CONTENT_CONTROL cannot used by 3rd party applications.根据Android 文档MEDIA_CONTENT_CONTROL 不能被 3rd 方应用程序使用。

MEDIA_CONTENT_CONTROL Added in API level 19 MEDIA_CONTENT_CONTROL在 API 级别 19 中添加

public static final String MEDIA_CONTENT_CONTROL

Allows an application to know what content is playing and control its playback.允许应用程序了解正在播放的内容并控制其播放。

Not for use by third-party applications due to privacy of media consumption由于媒体消费的隐私,不供第三方应用程序使用

Constant Value: "android.permission.MEDIA_CONTENT_CONTROL"常量值: "android.permission.MEDIA_CONTENT_CONTROL"

And there is no replacement for this one.这个没有替代品。 You can also check this How to get android permission of android.Manifest.permission.MEDIA_CONTENT_CONTROL您还可以查看如何获得 android.Manifest.permission.MEDIA_CONTENT_CONTROL 的 android 权限

代码是正确的,问题出在shoutcast服务器上,流是Android无法使用的某种格式,但可以从iOS使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM