为什么xcode在没有任何资源路径的情况下播放声音文件? [英] Why is xcode playing sound file without any path for resource?

查看:16
本文介绍了为什么xcode在没有任何资源路径的情况下播放声音文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以代码假设在第一次单击按钮时播放声音文件,并在再次单击同一按钮时播放另一种声音.我把所有 mp3 的声音文件放在一个文件夹中,它只播放文件是的(我还有其他声音,比如你好,你好,但是当我把它放在 pathforresouce 中时,它不播放它们),我收到了一个 nse 异常错误当我第二次单击按钮播放第二个声音时(进入构建阶段并且声音文件夹在那里但它没有在其他音频文件中播放,只有它播放?).因此,我取出了两个文件的资源位置路径,以检查我的声音文件是否正常工作并且仍在播放 yes 文件.当 yes 文件仅位于该声音文件夹中的一个位置时,这怎么可能?我什至从我的整个项目中取出了那个声音文件夹,它仍然在播放 yes,没有声音文件和路径资源?

Ok so the code is suppose to play the sound file when the button is first clicked and play another sound when that same button is clicked again. I put in a folder of sound files all mp3 and it only plays the file yes(I have other sounds like hello, but when I put that in the pathforresouce it does't play them), and I get an nse exception error when I click the button a second time to play the second sound(went into build phases and the sound folder is there but its not playin the other audio files, only yes it plays?). So I took out the path for resource location for both files to check if my sound files are working properly and it's still playing the yes file. How is this POSSIBLE, when the yes file is only in one location in that sound folder? I even took out that sound folder from my entire project and its still playing yes with no sound file and no pathforresource ?

    #import <AVFoundation/AVAudioPlayer.h>
    #import "ViewController.h"


    @interface ViewController ()


    @end
    int flag;

    @implementation ViewController
    AVAudioPlayer *theAudio;
    - (IBAction)Yes:(id)sender {


        if(flag==0){
          //play file one on first button click
            theAudio =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@""ofType:@"mp3"]] error:NULL];

            [theAudio play];
              flag=1;
        }

            else if(flag==1)
            {
          //play file second on first button click


                theAudio =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@""ofType:@"mp3"]] error:NULL];



                [theAudio play];
                           flag=0;

            }


    }
@end

推荐答案

已删除资源的剩余部分通常保留在模拟器上.

The leftovers of deleted resources often remain on simulator.

  1. 删除应用

  1. 清理项目并重试.

这篇关于为什么xcode在没有任何资源路径的情况下播放声音文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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