没有声音从AVPlayer未来 [英] No sound coming from AVPlayer

查看:198
本文介绍了没有声音从AVPlayer未来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用AVPlayer播放一个MP3(相机快门声)。我一直都剥离到一个简单的按钮,当pressed,播放的声音。所有这些对象都被正确创建,但是当我运行在任我的iPhone或iPad应用程序(包括运行iOS 6)不产生声音。不,静音按钮不亮,调高音量。 :)我可以听到声音的其他应用在两台设备上。

我做一些愚蠢的事?

   - (无效)playCameraShutterSound
{
    NSURL * URL = [[一个NSBundle mainBundle] URLForResource:@抢withExtension:@MP3];
    AVPlayer *玩家= [AVPlayer playerWithURL:URL]
    [播放器播放];
}


解决方案

玩家发行方法的末尾。
必须保留作为类变量。

I'm trying to play an mp3 (camera shutter sound) using AVPlayer. I've stripped everything down to a simple button that, when pressed, plays the sound. All of the objects are being created correctly but when I run the app on either my iPhone or iPad (both running iOS 6) no sound is generated. And no, the mute button is not on and the volume is turned up. :) I can hear sound in other apps on both devices.

Am I doing something stupid?

- (void)playCameraShutterSound
{
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"Grab" withExtension:@"mp3" ];
    AVPlayer* player = [AVPlayer playerWithURL:url];
    [player play];
}

解决方案

'player' is released the end of method. It must be reserved as a class variable.

这篇关于没有声音从AVPlayer未来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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