相关疑难解决方法(0)

如何在Swift中使用AVPlayerViewController(AVKit)播放视频

如何在Swift中使用AV Kit Player View Controller播放视频?

override func viewDidLoad() {
        super.viewDidLoad()
        let videoURLWithPath = "http://****/5.m3u8"
        let videoURL = NSURL(string: videoURLWithPath)
        playerViewController = AVPlayerViewController()

        dispatch_async(dispatch_get_main_queue()) {
            self.playerViewController?.player = AVPlayer.playerWithURL(videoURL) as AVPlayer
        }
    }
Run Code Online (Sandbox Code Playgroud)

avfoundation ios swift avkit avplayerviewcontroller

154
推荐指数
8
解决办法
18万
查看次数

AVAudioPlayer立即停止使用ARC播放

我正在尝试播放MP3,通过AVAudioPlayer它我认为相当简单.不幸的是,它并没有完全奏效.这就是我所做的一切:

  • 为了测试,我在Xcode中创建了一个新的iOS应用程序(Single View).
  • 我加入了AVFoundation框架到项目中,以及在#import <AVFoundation/AVFoundation.h>ViewController.m

  • 我在应用'文档'文件夹中添加了一个MP3文件.

  • 我改为ViewControllers viewDidLoad:以下内容:

码:

- (void)viewDidLoad
{
    [super viewDidLoad];        

    NSString* recorderFilePath = [NSString stringWithFormat:@"%@/MySound.mp3", [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]];    

    AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:recorderFilePath] error:nil];
    audioPlayer.numberOfLoops = 1;

    [audioPlayer play];

    //[NSThread sleepForTimeInterval:20];
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,音频在开始播放后显然会立即停止.如果我取消注释sleepForTimeInterval它会播放20秒并在之后停止.只有在使用ARC进行编译时才会出现此问题,否则,它会完美无缺地运行.

objective-c avfoundation avaudioplayer ios automatic-ref-counting

12
推荐指数
1
解决办法
7533
查看次数

SKAction playSoundFileNamed播放白噪声

我正在尝试使用SKAction播放aiff文件.此代码导致在模拟器和iPod上播放白噪声:

SKAction *sound = [SKAction playSoundFileNamed:@"noise1.aiff" waitForCompletion:NO];
[self runAction:sound];
Run Code Online (Sandbox Code Playgroud)

声音文件有效,它在我使用Amazing Audio Engine时有效.谁知道什么是错的?

谢谢

audio ios7 sprite-kit

6
推荐指数
1
解决办法
1503
查看次数

如何调试 AVAudioPlayer 播放失败?

我正在使用 AVAudioPlayer 从我的应用程序的 Documents 目录中播放单声道 AIFF 文件。

在模拟器上,[player play] 返回 YES 并且我听到文件正在播放。在设备上,播放方法返回 NO 并且什么也没有发生。我通过 Organizer 抓取了该文件 - 它在我的 Mac 上播放得很好,而且似乎格式正确。我意识到模拟器可以访问 iPhone 上不可用的编解码器,但这在这种情况下应该无关紧要,是吗?

我不知道如何调试它。有什么建议?

iphone avaudioplayer

5
推荐指数
1
解决办法
2738
查看次数

AVPlayer获取了元数据但没有播放

我正在尝试做一个非常简单的应用程序,目的是监听音频流(AAC 64 kbps).为此,我使用AVPlayerApple AVFoundation以下内容:

ViewController.m

#import "ViewController.h"
@interface ViewController ()
@end

@implementation ViewController
@synthesize playerItem, player;

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void) viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    playerItem = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:@"http://stream.myjungly.fr/MYJUNGLY2"]];
    [playerItem addObserver:self forKeyPath:@"timedMetadata" options:NSKeyValueObservingOptionNew context:nil];

    player = [AVPlayer playerWithPlayerItem:playerItem];
    [player play];

    NSLog(@"player item error : %@", playerItem.error.description);
    NSLog(@"player error : %@", player.error.description);
}

- (void) observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object
                     change:(NSDictionary*)change context:(void*)context {

    if ([keyPath isEqualToString:@"timedMetadata"])
    {
        AVPlayerItem* _playerItem = object;
        for (AVMetadataItem* metadata in …
Run Code Online (Sandbox Code Playgroud)

objective-c avfoundation audio-streaming avplayer

3
推荐指数
1
解决办法
2557
查看次数

Objective-C 无法使用 AVAudioPlayer 播放声音

我在 iOS 9 上使用 XCode 7,我正在尝试播放声音。我一直在谷歌上搜索解决方案好几天了,我已经尝试了所有可能的解决方案,但没有任何效果。

这是我的代码

。H

#import <AudioToolbox/AudioToolbox.h>
#import <AVFoundation/AVFoundation.h>

@interface ViewController : UIViewController <DTDeviceDelegate, AVAudioPlayerDelegate>
{

}
Run Code Online (Sandbox Code Playgroud)

这是我的 .m 文件:

 NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"autumn_leaves" ofType:@"m4a"];

    NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];

    NSError *error;

    AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL
                                                                   error:&error];
    player.numberOfLoops = -1; //Infinite

    [player play];
Run Code Online (Sandbox Code Playgroud)

没有声音,没有错误,没有警告,什么都没有

soundFilePath并且soundFileURL不是nil,与玩家一样,他们越来越多。我的电话音量尽可能大。

我也在 .m 文件中尝试过:

@property(strong, nonatomic) AVAudioPlayer *player;

self.myPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:fileURL error:&error];
[self.myPlayer play];
Run Code Online (Sandbox Code Playgroud)

也没有播放声音,也没有错误。

这是我的资源文件夹的屏幕截图:

在此处输入图片说明

请帮忙!

audio xcode objective-c avaudioplayer ios

2
推荐指数
1
解决办法
6702
查看次数