小编nem*_*sis的帖子

AVAUdioPlayer - 更改当前URL

在我的音频播放器应用程序中,如果我点击快进按钮 - 播放器必须找到播放列表中的下一首歌并播放它.我所做的是从下一首歌中获取URL,并尝试将其放在后台(后台是AVAudioPlayer*的实例)url字段,但该属性是只读的.所以我实际上在做什么 - 我正在调用initWithContentsOfURL方法(再次)来设置这样的URL:

[self.background initWithContentsOfURL:
[[_playlist.collection objectAtIndex:currentIndex] songURL] error:nil];
Run Code Online (Sandbox Code Playgroud)

这是合法的吗?我的意思是,编译器告诉我表达式结果未使用,但它实际上是有效的.还有另一种方法吗?谢谢 ;-)

avaudioplayer ios

4
推荐指数
1
解决办法
9650
查看次数

正确裁剪和缩放UIImage

我正在尝试将图像裁剪成方形,然后将其缩放到200x200的大小.这是我使用的代码,但它并不适合我.我得到的图像有时处于不同的方向,或者没有从中心裁剪,或者比它应该更宽.

float scale = _avatar.image.scale;
UIImageOrientation orientation = _avatar.image.imageOrientation;

if(_avatar.image.size.width < _avatar.image.size.height){ // avatar is a UIImageView
    float startingY = (_avatar.image.size.height-_avatar.image.size.width)/2; // image is taller, determine the origin of the width-sized square, which will be the new image
    CGImageRef imageRef = CGImageCreateWithImageInRect([_avatar.image CGImage], CGRectMake(0, startingY, _avatar.image.size.width, _avatar.image.size.width));
    _avatar.image = [UIImage imageWithCGImage:imageRef scale:scale orientation:orientation];
    CGImageRelease(imageRef);
} else {
    float startingX = (_avatar.image.size.width-_avatar.image.size.height)/2; // image is wider, determine the origin of the height-sized square, which will be the new image
    CGImageRef imageRef …
Run Code Online (Sandbox Code Playgroud)

resize core-graphics crop uiimage ios

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

更新iOS 5中的进度条

我正在开发一个iOS音频播放器,我想实现一个进度条,它将指示正在播放的当前歌曲的进度.在我的ViewController类中,我有2个双实例 - 时间和持续时间,以及一个名为background的AVAudioPlayer实例.

- (IBAction)play:(id)sender {
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"some_song" ofType:@"mp3"];
    NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];
    background = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];
    background.delegate = self;
    [background setNumberOfLoops:1];
    [background setVolume:0.5];
    [background play];
    time = 0;
    duration = [background duration];
    while(time < duration){
        [progressBar setProgress: (double) time/duration animated:YES];
        time += 1; 
    } 
}
Run Code Online (Sandbox Code Playgroud)

谁能解释我做错了什么?提前致谢.

iphone avaudioplayer ios progress-bar

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

iOS 5链接器错误

编辑一些代码后,我得到4个构建错误:

Undefined symbols for architecture i386:
"_OBJC_CLASS_$_Playlist", referenced from:
  objc-class-ref in PlayerViewController.o
"_OBJC_CLASS_$_Song", referenced from:
  objc-class-ref in PlayerViewController.o
"_currentIndex", referenced from:
  -[PlayerViewController viewDidLoad] in PlayerViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)

关于如何解决这个问题的任何提示?

linker-errors ios5

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

iOS 5.x - 检测用户何时单击搜索文本字段

如何检测用户何时按下通用搜索栏中的空文本字段?

xcode objective-c searchbar ios5

0
推荐指数
1
解决办法
2852
查看次数