加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何在iOS应用程序中播放m3u音频流

发布时间:2020-12-15 01:41:13 所属栏目:百科 来源:网络整理
导读:我正在尝试使用Xcode 4.5.2创建一个iOS / iPhone无线电应用程序. 我想通过播放,暂停,音量控制来播放@“http://xx.xxxxxxx.com/8111/radio.m3u”并能够播放背景功能/多任务处理. 到目前为止,我已经添加了AVFoundation,Mediaplayer和AudioToolBox框架.我已经为
我正在尝试使用Xcode 4.5.2创建一个iOS / iPhone无线电应用程序.

我想通过播放,暂停,音量控制来播放@“http://xx.xxxxxxx.com/8111/radio.m3u”并能够播放背景功能/多任务处理.

到目前为止,我已经添加了AVFoundation,Mediaplayer和AudioToolBox框架.我已经为xib添加了播放,暂停和滑块对象.

ViewController.h

@interface ViewController : UIViewController

@property (strong,nonatomic) MPMoviePlayerController *myPlayer;

@property (weak,nonatomic) IBOutlet UISlider *myslider;

- (IBAction)playButtonPressed;

- (IBAction)myslider:(id)sender;

@end

ViewController.m
#import "ViewController.h"
#import <MediaPlayer/MediaPlayer.h>

@interface ViewController ()
{
    UISlider *volumeSlider;
}

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
    UIBackgroundTaskIdentifier newTaskId = UIBackgroundTaskInvalid;
    newTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];
}

- (IBAction)playButtonPressed;
{
    NSString *urlAddress = @"http://xxxxxxx.com/8111/listen.m3u";
    NSURL *url = [NSURL URLWithString:urlAddress];
    MPMoviePlayerController *player = [[MPMoviePlayerController alloc]initWithContentURL:url];
    player.movieSourceType = MPMovieSourceTypeStreaming;
    [player prepareToPlay];
    self.myPlayer = player;
    [self.view addSubview:self.myPlayer.view];
    [self.myPlayer play];
}

- (IBAction)stopButtonPressed;
{
    [self.myPlayer stop];
}
- (IBAction)myslider:(id)sender
{
    MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame: CGRectMake(10,10,200,40)];
    [volumeSlider addSubview:volumeView];
    [volumeView sizeToFit];
    }

解决方法

实现这一目标有两种方法.

>您可以直接在UIWebView中加载URL,它将正确.>您也可以使用MPMoviePlayerController.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读