请问各位朋友,如何实现在iphone上直接播放在线的视频呢

解决方案 »

  1.   


    -(id)init
    {
    if(self = [super init])
    {
    [[NSNotificationCenter defaultCenter] addObserver:self 
     selector:@selector(moviePreloadDidFinish:) 
     name:MPMoviePlayerContentPreloadDidFinishNotification 
     object:nil];
     
     // Register to receive a notification when the movie has finished playing. 
     [[NSNotificationCenter defaultCenter] addObserver:self 
     selector:@selector(moviePlayBackDidFinish:) 
     name:MPMoviePlayerPlaybackDidFinishNotification 
     object:nil];
     
     // Register to receive a notification when the movie scaling mode has changed. 
     [[NSNotificationCenter defaultCenter] addObserver:self 
     selector:@selector(movieScalingModeDidChange:) 
     name:MPMoviePlayerScalingModeDidChangeNotification 
     object:nil];
    return self;

    }
    return nil;
    }-(void)playMovie:(Contentinfo*)info
    {


    if (moviePlayer != nil) 
    {
    [moviePlayer release];
    moviePlayer = nil;
    }
    NSURL* url = nil;

    if ([info.pathUrl hasPrefix:@"http://"])
    {

    url = [NSURL URLWithString:info.pathUrl];
    }
    else 
    {

    NSString* fullPath = [DataUtil getContentFilePath:info.pathUrl];
    NSLog(@"%@",fullPath);
    url = [NSURL fileURLWithPath:fullPath];
    } if (url != nil) 
    {
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
    moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
    moviePlayer.movieControlMode = MPMovieControlModeDefault;
    musicIsPlaying = [[MusicPlayerEngine shareInstence] isPlaying];
    if (musicIsPlaying) 
    {
    [[MusicPlayerEngine shareInstence] pause];
    }


    self.Info=info;


    [moviePlayer play];
    }
    }//视频已准备好播放
    - (void) moviePreloadDidFinish:(NSNotification*)notification
    {
    NSArray *windows = [[UIApplication sharedApplication] windows];
    if ([windows count] > 1)
    {
    UIWindow *moviePlayerWindow = [[UIApplication sharedApplication] keyWindow];
    UIImageView* view = (UIImageView*)[moviePlayerWindow viewWithTag:LOADING_VIEW_TAG];
    if (view != nil) {
    [view removeFromSuperview];
    }
    }


    if (0==[[notification userInfo] count])
    { //将系统时间给contentInfo对象
    NSString *a=[NSString stringWithString:[self getTime]];
    Info.lastPlayedTime=a;
    //将contentInfo对象添加到最近播放列表
    [[DataBase sharedInstance] addContentInfoToRecentPlayList:self.Info];
    }    NSLog(@"moviePreloadDidFinish");
    }
    //视频已播放结束
    - (void) moviePlayBackDidFinish:(NSNotification*)notification
    {
        NSLog(@"moviePlayBackDidFinish");

              

    if (musicIsPlaying) {
    [[MusicPlayerEngine shareInstence] playMusic];
    }
    //begin zhaozhou mv播放界面退出后,刷新最近播放界面
    [self.delegate reloadRecentPlayTableView:self];
    //end

    }
    //视频比例模式发生改变。
    - (void) movieScalingModeDidChange:(NSNotification*)notification
    {
        NSLog(@"movieScalingModeDidChange");

    }