streaming a video into a web player using javacsript (react component)

I am using Javascript, however the possibly important caveat is in a WebView. I have a stream of data which is an mp4 that I can retrieve like so

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> window.runtime.EventsOn('playback-continue', (chunk) => {
console.log("chunk ", chunk)
queue.push(new Uint8Array(chunk));
appendToBuffer(sourceBuffer);
});
</code>
<code> window.runtime.EventsOn('playback-continue', (chunk) => { console.log("chunk ", chunk) queue.push(new Uint8Array(chunk)); appendToBuffer(sourceBuffer); }); </code>
            window.runtime.EventsOn('playback-continue', (chunk) => {
                console.log("chunk ", chunk)
                queue.push(new Uint8Array(chunk));
                appendToBuffer(sourceBuffer);
            });

I have no issues retrieving the bytes this way (if i print the chunk i can see the data albeit its printed in base64).

However I can’t seem to be able to use this to stream a video into a player.

My component looks like

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>
const VideoPlayer = () => {
const videoRef = useRef(null);
const mimeCodec = 'video/mp4; codecs="avc1.4D401F"';
let queue = [];
const mediaSource = new MediaSource();
useEffect(() => {
if (!('MediaSource' in window) || !MediaSource.isTypeSupported(mimeCodec)) {
console.error('Unsupported MIME type or codec: ', mimeCodec);
return;
}
const video = videoRef.current;
video.srcObject = mediaSource;
mediaSource.addEventListener('sourceopen', () => {
const sourceBuffer = mediaSource.addSourceBuffer(mimeCodec);
window.runtime.EventsOn('playback-continue', (chunk) => {
console.log("chunk ", chunk)
queue.push(new Uint8Array(chunk));
appendToBuffer(sourceBuffer);
});
window.runtime.EventsOn('playback-end', () => {
mediaSource.endOfStream();
});
function appendToBuffer(sourceBuffer) {
if (queue.length > 0 && !sourceBuffer.updating && mediaSource.readyState === 'open') {
sourceBuffer.appendBuffer(queue.shift());
}
}
sourceBuffer.addEventListener('updateend', () => appendToBuffer(sourceBuffer));
sourceBuffer.addEventListener('error', (e) => console.error('SourceBuffer error:', e));
});
return () => {
window.runtime.EventsOff('playback-continue');
window.runtime.EventsOff('playback-end');
};
}, []);
const startStreaming = () => {
const videoPath = '/Users/username/Desktop/video.mp4'; // Change to your actual video file path
OpenVideoFile(videoPath);
};
const stopStreaming = () => {
mediaSource.endOfStream();
};
return (
<div>
<button onClick={startStreaming}>Start Streaming</button>
<button onClick={stopStreaming}>Stop Streaming</button>
<video ref={videoRef} controls />
</div>
);
};
</code>
<code> const VideoPlayer = () => { const videoRef = useRef(null); const mimeCodec = 'video/mp4; codecs="avc1.4D401F"'; let queue = []; const mediaSource = new MediaSource(); useEffect(() => { if (!('MediaSource' in window) || !MediaSource.isTypeSupported(mimeCodec)) { console.error('Unsupported MIME type or codec: ', mimeCodec); return; } const video = videoRef.current; video.srcObject = mediaSource; mediaSource.addEventListener('sourceopen', () => { const sourceBuffer = mediaSource.addSourceBuffer(mimeCodec); window.runtime.EventsOn('playback-continue', (chunk) => { console.log("chunk ", chunk) queue.push(new Uint8Array(chunk)); appendToBuffer(sourceBuffer); }); window.runtime.EventsOn('playback-end', () => { mediaSource.endOfStream(); }); function appendToBuffer(sourceBuffer) { if (queue.length > 0 && !sourceBuffer.updating && mediaSource.readyState === 'open') { sourceBuffer.appendBuffer(queue.shift()); } } sourceBuffer.addEventListener('updateend', () => appendToBuffer(sourceBuffer)); sourceBuffer.addEventListener('error', (e) => console.error('SourceBuffer error:', e)); }); return () => { window.runtime.EventsOff('playback-continue'); window.runtime.EventsOff('playback-end'); }; }, []); const startStreaming = () => { const videoPath = '/Users/username/Desktop/video.mp4'; // Change to your actual video file path OpenVideoFile(videoPath); }; const stopStreaming = () => { mediaSource.endOfStream(); }; return ( <div> <button onClick={startStreaming}>Start Streaming</button> <button onClick={stopStreaming}>Stop Streaming</button> <video ref={videoRef} controls /> </div> ); }; </code>

const VideoPlayer = () => {
    const videoRef = useRef(null);
    const mimeCodec = 'video/mp4; codecs="avc1.4D401F"';
    let queue = [];
    const mediaSource = new MediaSource();
    useEffect(() => {
        if (!('MediaSource' in window) || !MediaSource.isTypeSupported(mimeCodec)) {
            console.error('Unsupported MIME type or codec: ', mimeCodec);
            return;
        }


        const video = videoRef.current;
        video.srcObject = mediaSource;

        mediaSource.addEventListener('sourceopen', () => {
            const sourceBuffer = mediaSource.addSourceBuffer(mimeCodec);

            window.runtime.EventsOn('playback-continue', (chunk) => {
                console.log("chunk ", chunk)
                queue.push(new Uint8Array(chunk));
                appendToBuffer(sourceBuffer);
            });

            window.runtime.EventsOn('playback-end', () => {
                mediaSource.endOfStream();
            });

            function appendToBuffer(sourceBuffer) {
                if (queue.length > 0 && !sourceBuffer.updating && mediaSource.readyState === 'open') {
                    sourceBuffer.appendBuffer(queue.shift());
                }
            }

            sourceBuffer.addEventListener('updateend', () => appendToBuffer(sourceBuffer));
            sourceBuffer.addEventListener('error', (e) => console.error('SourceBuffer error:', e));
        });

        return () => {
            window.runtime.EventsOff('playback-continue');
            window.runtime.EventsOff('playback-end');
        };
    }, []);

    const startStreaming = () => {
        const videoPath = '/Users/username/Desktop/video.mp4'; // Change to your actual video file path
        OpenVideoFile(videoPath);
    };
    const stopStreaming = () => {
        mediaSource.endOfStream();
    };
    return (
        <div>
            <button onClick={startStreaming}>Start Streaming</button>
            <button onClick={stopStreaming}>Stop Streaming</button>
            <video ref={videoRef} controls />
        </div>
    );
};

I have tried to find blogs/tutorials but I think the issue is how I am passing the stream to the player, not the player code itself.
I just don’t see anything except a continual spinner on the player

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật