Hi,

The code I’m using is as follows: (it works well and videos plays when logged 
in as admin user, but doesn’t play when the app is run as root):

In awakeFromNib:
        [[avPlayerView layer] 
setBackgroundColor:CGColorGetConstantColor(kCGColorClear)];
        // Create the AVPlayer, add rate and status observers
        avPlayer = [[AVPlayer alloc] init];// autorelease];
        // Create an asset with our URL, asychronously load its tracks, its 
duration, and whether it's playable or protected.
        // When that loading is complete, configure a player to play the asset.
        NSURL *fileURL = [[NSBundle mainBundle] 
URLForResource:@"progress-movie" withExtension:@"mov"];
        AVURLAsset *asset = [AVAsset assetWithURL:fileURL];
        NSArray *assetKeysToLoadAndTest = [NSArray 
arrayWithObjects:@"playable", @"hasProtectedContent", @"tracks", @"duration", 
nil];
        [asset loadValuesAsynchronouslyForKeys:assetKeysToLoadAndTest 
completionHandler:^(void) {
                // The asset invokes its completion handler on an arbitrary 
queue when loading is complete.
                // Because we want to access our AVPlayer in our ensuing 
set-up, we must dispatch our handler to the main queue.
                dispatch_async(dispatch_get_main_queue(), ^(void) {
                        [self setUpPlaybackOfAsset:asset 
withKeys:assetKeysToLoadAndTest];
                });
        }];

- (void)playVideo {
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             
selector:@selector(playerItemDidReachEnd:)
                                                 
name:AVPlayerItemDidPlayToEndTimeNotification
                                               object:[avPlayer currentItem]];
    avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
    [avPlayer seekToTime:kCMTimeZero];
    [avPlayer play];
}

- (void)pauseVideo {
    [avPlayer pause];
    [[NSNotificationCenter defaultCenter] removeObserver:self 
name:AVPlayerItemDidPlayToEndTimeNotification object:[avPlayer currentItem]];
}

- (void)playerItemDidReachEnd:(NSNotification *)notification {
    AVPlayerItem *p = [notification object];
    [p seekToTime:kCMTimeZero];
}

- (void)setUpPlaybackOfAsset:(AVAsset *)asset withKeys:(NSArray *)keys
{
        // Set up an AVPlayerLayer according to whether the asset contains 
video.
        if ([[asset tracksWithMediaType:AVMediaTypeVideo] count] != 0)
        {
                // Create an AVPlayerLayer and add it to the player view if 
there is video, but hide it until it's ready for display
                AVPlayerLayer *newPlayerLayer = [AVPlayerLayer 
playerLayerWithPlayer:avPlayer];
                [newPlayerLayer setFrame:[[avPlayerView layer] bounds]];
                [newPlayerLayer setAutoresizingMask:kCALayerWidthSizable | 
kCALayerHeightSizable];
                //[newPlayerLayer setHidden:YES];
                avPlayerLayer = newPlayerLayer;
                [avPlayerLayer retain];
                [[avPlayerView layer] addSublayer:newPlayerLayer];
        }
        // Create a new AVPlayerItem and make it our player's current item.
        AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset];
        [avPlayer replaceCurrentItemWithPlayerItem:playerItem];
}

Can it work when app is running as root?
Please help.


Best,
Navneet

_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to