在后台音频播放,但没有声音科尔多瓦3+ IOS [英] Audio plays in background but no sound Cordova 3+ IOS

查看:203
本文介绍了在后台音频播放,但没有声音科尔多瓦3+ IOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在播放MP3文件。我用科尔多瓦3+
我使用

I'm playing a mp3 file. I used cordova 3+ I'm using

snd = new Media(source,onSuccess,onplayError,mediaStatus);
snd.setVolume(current_volume);                      
snd.play();

一切顺利。然后,我将这些在的info.plist

Application does not run in background - NO
Required background modes:
Item0 - Audio...............etc.

然后我尝试这种

if ([resourceURL isFileURL]) {
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
    audioFile.player = [[ AVAudioPlayer alloc ] initWithContentsOfURL:resourceURL error:&error];
} else {
    NSData* data = [NSData dataWithContentsOfURL:resourceURL];
    audioFile.player = [[ AVAudioPlayer alloc ] initWithData:data error:&error];
}

这是从这里 http://www.joeldare.com/wiki/play_an_mp3_audio_stream_in_phonegap 发现

虽然我发现sound.m文件是不存在的描述。我发现在插件文件夹该文件。而这些线条是近线没有。 363

Though I found that sound.m file wasn't there as described. I found that file in plugin folder. And those lines were near line no. 363

然后我试图播放音频。接下来,我pressed home键。没有声音来自于iPhone模拟器。我preesed再次应用程序图标后,应用程序的UI来到前面,声音可以好像是一直打听到。手段假设我有后,从家里按钮preSS,那么歌曲是从当前1分钟打1分钟pressed的应用程序图标。所以首歌其实是打不过的声音不能在之后pressing home键的期间heared。希望我解释正确的。

Then I tried to play the audio. Next I pressed the home button. No sound came from the iphone emulator. After that I preesed the app icon again, app ui came to front and sound can be heard as if it was playing all along. Means suppose I have pressed the app icon after 1 minute from the home button press, then the song is playing from 1 minute currently. So song was actually playing but sound can't be heared during that period after pressing home key. Hope I explained it properly.

谁能告诉我,我缺少的是什么?我想被heared声音甚至在home键是pressed或电话被锁定或显示下车。请大家帮帮忙.......

Can anyone please tell me what I'm missing? I want the sound to be heared even after home key is pressed or phone gets locked or display gets off. Please help.......

此外如果我使用HTML5的音频播放器后,我已经做处理这个'home键preSS'的问题最小化后播放音频?

Also if I use html5 audio player, what I've to do to handle this 'home key press' problem to play the audio after minimization?

推荐答案

首先,这样做,我在写的问题,那些东西。然后导入AVFoundation到 AppDelegate.m #进口< AVFoundation / AVFoundation.h>

First,DO those things that I wrote in question. Then import AVFoundation into your AppDelegate.m #import <AVFoundation/AVFoundation.h>

然后添加以下应用程序:(*的UIApplication)的应用didFinishLaunchingWithOptions:(NSDictionary的*)launchOptions

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
BOOL ok;
NSError *setCategoryError = nil;
ok = [audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError];

从这里找到 https://github.com/devgeeks/ExampleHTML5AudioStreaming

在测试真实的设备,而不是在模拟器。背景音乐不工作
  针对仿真。

TEST IN REAL DEVICE, NOT IN SIMULATOR. BACKGROUND AUDIO DOESN'T WORK WITH SIMULATOR.

这篇关于在后台音频播放,但没有声音科尔多瓦3+ IOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆