[MobileVLCKit (3.5.1)] Does NOT play while downloading video with NSInputStream as resource
Hello,
I used socket to fetch video data and set them to NSInputStream, but after I used NSInputStream as VLCMedia resource, I met an issue that app cannot play while downloading video. I used the below code to create VLCMedia and VLCMediaPlayer objects:
let options = ["--reset-config",
"--ignore-config",
"--no-input-fast-seek",
"--file-caching=2000",
"--verbose=2",
"--no-osd",
"--no-snapshot-preview",
"--codec=avcodec",
"--avcodec-hw=none",
"--network-caching=10000"
]
let stream = self.socket?.inputStream
let media = VLCMedia(stream: stream!)
let _player = VLCMediaPlayer(options: options)
self.media = media
_player.media = media
_player.delegate = self
_player.drawable = self.outputView
_player.play()
self.player = _player
when vlc read the cache data from inputStream and the length of cache data is not zero, vlc player will not play the downloading video data, and then once the length of cache data in the inputStream is zero, vlc player will play the video data, however, after that, I continue to add data from socket to cache data of inputStream, VLC does not read and play video data any more.
I also tried using semaphore to prevent the cache data length from being 0, but vlc player does not always play video while downloading.
code to read function in the NSInputStream
- (NSInteger)read:(uint8_t *)buffer maxLength:(NSUInteger)length {
NSInteger totalNumberOfBytesRead = 0;
if ([self streamStatus] == NSStreamStatusClosed) {
return totalNumberOfBytesRead;
}
@synchronized (self.clips) {
if (self.clips.count == 0) {
// dispatch_semaphore_wait(semaphore0, DISPATCH_TIME_FOREVER);
return totalNumberOfBytesRead; // it will be commented if semaphore is enabled
}
self.reminder = [self.clips firstObject];
totalNumberOfBytesRead = self.reminder.length;
[self.reminder getBytes:buffer range:NSMakeRange(0, totalNumberOfBytesRead)];
[self.clips removeObjectAtIndex:0];
}
return totalNumberOfBytesRead;
}
if I want to implement app can play video while downloading with NSInputStream, do I need add other process? please help give me some suggestion. Appreciated for your help
Thanks