Search code examples
iosobjective-ciphonecachingvlc

Caching in VLC Media Player


I'm using VLC Media Player (MobileVLCKit.framwork) for playing .mpd format file. In the case of AVCaching Player, we have option for caching but in this case I'm not able to add caching feature. I tried but not getting any info about solving this problem. It would be great if any body can give few ideas to solve this problem. I'm working on iOS development.

This is the code for AVcaching player catch and want the same for VLC Media Player caching.

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{

    Log(@"response received");

    if(self.videoCacheObject.response == nil){
        self.videoCacheObject.response = (NSHTTPURLResponse *)response;
    }

    if([self.delegate respondsToSelector:@selector(requestDidReceiveResponse)]){
        [self.delegate requestDidReceiveResponse];
    }
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
    [self.videoCacheObject.videoData appendData:data];

    Log(@"video data length = %lu", (unsigned long)self.videoCacheObject.videoData.length);

    if(self.videoCacheObject.videoData.length > PARTIAL_LOAD_LENGTH * self.videoCacheObject.response.expectedContentLength && shouldLoadPartial){
        [[TMCache sharedCache] setObject:self.videoCacheObject forKey:self.videoName];
        [self.connection cancel];

        if([self.delegate respondsToSelector:@selector(requestPrefetchingCompleted)]){
            Log(@"prefetching completed");
            [self.delegate requestPrefetchingCompleted];
        }
    }
    else if(self.videoCacheObject.videoData.length > 0.15*self.videoCacheObject.response.expectedContentLength){
        [[TMCache sharedCache] setObject:self.videoCacheObject forKey:self.videoName];
    }

    if([self.delegate respondsToSelector:@selector(requestDidReceiveData)]){
        [self.delegate requestDidReceiveData];
    }
}

Solution

  • MobileVLCKit does not allow you to do caching this way.

    You basically have 2 options:

    • trust VLC that it is doing the right thing (or provide "--network-caching" as an option with the desired buffer size in milliseconds, default is 300)
    • cache the media yourself as a file and ask VLC to play that file. Just like with desktop VLC, the file does not need to be complete to be played for most formats.

    Future versions of MobileVLCKit will add a third option, namely a memory input module to VLC, so you can provide your data in memory without storing them to a local first, but this won't be ready for production before fall this year.