【问题标题】:Expo AV Audio not audible on iosiOS 上听不到 Expo AV 音频
【发布时间】:2022-11-19 01:24:36
【问题描述】:

大家好,我正在使用 Expo AV 在我的 React Native(Expo 管理的)应用程序中播放声音,音频在 android 上播放得很好而且听得见,但在 ios 上播放时声音不大听得见,苹果也拒绝了 App Store 上的应用程序因为这

他们说

您的应用在 Info.plist 的 UIBackgroundModes 键中声明支持音频,但不包含需要持久音频的功能。
下一步
音频密钥旨在供在后台向用户提供音频内容的应用程序使用,例如音乐播放器或流式音频应用程序。请修改您的应用程序以在应用程序处于后台时向用户提供音频内容,或者从 UIBackgroundModes 键中删除“音频”设置。

这是 expo-av 音频模式设置

Audio.setAudioModeAsync({
        staysActiveInBackground: true,
        shouldDuckAndroid: true,
        interruptionModeIOS: 1,
        interruptionModeAndroid: 1,
        allowsRecordingIOS: true,
        playsInSilentModeIOS: false,
})

我像这样播放音频

const {sound} = await Audio.Sound.createAsync(
          {uri: audioURI},
          {
            shouldPlay: true,
          }
        );

这是导入语句

import { Audio } from 'expo-av';

我不知道它是否是由我在应用程序中用于音乐控件的 React Native Music Control 库引起的

像进口的

import MusicControl from 'react-native-music-control'

我在播放音频后立即调用它

MusicControl.setNowPlaying({
            title: currentAudio.title,
            artwork: currentAudio.imageUrl, // URL or RN's image require()
            artist: currentAudio.artist,
            genre: currentAudio.genre,
            duration: (minutesToMilliseconds(currentAudio.playtime) / 1000), // (Seconds)
            description: currentAudio.description, // Android Only
            color: 0xffffff, // Android Only - Notification Color
            colorized: true, // Android 8+ Only - Notification Color extracted from the artwork. Set to false to use the color property instead
            isLiveStream: false, // iOS Only (Boolean), Show or hide Live Indicator instead of seekbar on lock screen for live streams. Default value is false.
        })

请问我做错了什么,在此先感谢您的帮助

【问题讨论】:

    标签: ios react-native audio expo expo-av


    【解决方案1】:

    我修好了

    如何?

    我认为是 react-native-music-control 引起的,我在一个函数中配置了 Expo AV Audio 和 react-native-music-control,并在应用程序的一个主要文件中的 React.useLayoutEffect 中调用了该函数

    但我发现,如果我改变了功能中的某些东西,音频就会被听到

    所以我所做的就是在调用Audio.Sound.createAsync(...)之后调用该函数

    const {sound} = await Audio.Sound.createAsync(
     { uri: audioDetails.url, },
               {
                 shouldPlay: true,
               },
               (status: AVPlaybackStatus) => 
               onPlaybackStatusUpdate(...),
               false
              
             );
           useAppGlobalContextIn.initializeMusicControl() // the function where I called the Expo AV Audio and the MusicControl setup
    

    这有点棘手,但是当我遇到 Expo AV Audio 的另一个问题时,我决定更改为 react-native-track-player,它完美地工作,它处理 Expo AV Audio 和 react-native-music-control 的功能,还提供令人难以置信的工作事件与远程事件

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-03
      • 2022-09-23
      • 2022-08-22
      • 1970-01-01
      • 1970-01-01
      • 2022-09-29
      • 2020-06-30
      相关资源
      最近更新 更多