小编Ash*_*ein的帖子

IOS AVPlayer不会播放视频

我正在尝试播放视频,因此我从教程中获得了一些代码,但它无法正常工作.

这是我使用的代码:

- (void) viewDidAppear:(BOOL)animated
{
    avAsset = [AVAsset assetWithURL:[NSURL URLWithString:filePath]];
    avPlayerItem =[avPlayerItem initWithAsset:avAsset];
    avPlayer = [AVPlayer playerWithPlayerItem:avPlayerItem];
    avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:avPlayer];
    [avPlayerLayer setFrame:self.view.frame];
    [self.view.layer addSublayer:avPlayerLayer];
    [avPlayer seekToTime:kCMTimeZero];
    [avPlayer play];

}
Run Code Online (Sandbox Code Playgroud)

我不知道它有什么不对,它没有给出任何错误它只是给了黑屏.谢谢.

video ios avplayer ios6

6
推荐指数
2
解决办法
3万
查看次数

将uilabel和uiimageview保存为uiimage

我正在尝试向图像添加文本,但uilabel在a中添加as子视图uiimageview.我已经这样做但我想将它们保存为图像; 我在上下文中使用渲染,但它不起作用.

这是我的代码:

UIImage * img = [UIImage imageNamed:@"IMG_1650.JPG"];

        float x = (img.size.width/imageView.frame.size.width) * touchPoint.x;
        float y = (img.size.height/imageView.frame.size.height) * touchPoint.y;

        CGPoint tpoint = CGPointMake(x, y);

        UIFont *font = [UIFont boldSystemFontOfSize:30];
        context = UIGraphicsGetCurrentContext();
        UIGraphicsBeginImageContextWithOptions(img.size, YES, 0.0);
        [[UIColor redColor] set];

        for (UIView * view in [imageView subviews]){
            [view removeFromSuperview];
        }
             UILabel * lbl = [[UILabel alloc]init];
        [lbl setText:txt];
        [lbl setBackgroundColor:[UIColor clearColor]];
        CGSize sz = [txt sizeWithFont:lbl.font];
        [lbl setFrame:CGRectMake(touchPoint.x, touchPoint.y, sz.width, sz.height)];
        lbl.transform = CGAffineTransformMakeRotation( -M_PI/4 ); …
Run Code Online (Sandbox Code Playgroud)

uiimage uilabel imageview ios

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

IOS切换AVFoundation相机

在我的应用程序中,我使用AVFoundation捕获图像

我做了一个按钮,在前后摄像头之间切换,但是不起作用.

这是我使用的代码:

if (captureDevice.position == AVCaptureDevicePositionFront) {
        for ( AVCaptureDevice *device in [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo] ) {
            if ( device.position == AVCaptureDevicePositionBack) {


                NSError * error;
                AVCaptureDeviceInput * newDeviceInput = [[AVCaptureDeviceInput alloc]initWithDevice:device error:&error];
                [captureSesion beginConfiguration];
                for (AVCaptureDeviceInput *oldInput in [captureSesion inputs]) {
                    [captureSesion removeInput:oldInput];
                }

                if ([captureSesion canAddInput:newDeviceInput]) {
                    [captureSesion addInput:newDeviceInput];
                }                
                [captureSesion commitConfiguration];
                break;
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

谢谢.

camera avfoundation ios avcapturesession

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