Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{Question] Stream from file #1774

Open
alexsafe opened this issue Mar 26, 2025 · 5 comments
Open

{Question] Stream from file #1774

alexsafe opened this issue Mar 26, 2025 · 5 comments

Comments

@alexsafe
Copy link

Hi,

I want to be able to play a file while streaming on the device. Using preview is fine but I want to be able to loop that video.

I see there is a playAudioDevice() in FromFileBase which is exactly what I would like for video, but that part seems to be missing.

Any idea on how can I play the video too? Maybe I'm missing something... I am using GenericFromFile, but I don't see any relevant difference with RtmpFromFile from example.

And also, is it possible to achieve the same results (play video+audio on the device too with loop) with GenericStream and changeVideoSource(videoFileSource)?

@pedroSG94
Copy link
Owner

I don't understand you.
If you means loop a video using FromFileBase. You already have a example in app module with loop enabled:
https://github.com/pedroSG94/RootEncoder/blob/master/app/src/main/java/com/pedro/streamer/file/FromFileActivity.kt#L108

If you want loop a video/audio file using GenericStream, you can use VideoFileSource or AudioFileSource or both. In both, you can select if you want loop in the constructor and change it on real time using setLoopMode method (by default loop enabled).

About play the audio of the file using AudioFileSource. Yes, you can do it. You have a method with the same name that using FromFileBase (playAudioDevice and stopAudioDevice).

About GenericFromFile and RtmpFromFile. The difference is that GenericFromFile support all stream protocols but you only can use methods and codecs commons in all protocols. Using RtmpFromFile you can use all codecs and methods supported by RTMP. The usage depend of your needs.
In the app example I'm using GenericFromFile to allow users test all protocols

@alexsafe
Copy link
Author

My problem is that when I stream from file I am not getting the video on my device. I can see the stream being published and I see it remotely, just not on my device. If I add playAudioDevice() to the startStream() then I can hear the audio on my device. But ofc , still no video.

In your example FromFileActivity it seems to me that video is played (on the device) only if recording?

So yeah basically my question is about seeing the video from the file stream on the device screen. Currently, with this code it only shows remotely.

rtmpFromFile.playAudioDevice()
rtmpFromFile?.startStream(rtmpUrl)

@pedroSG94
Copy link
Owner

Hello,

Are you using an OpenGlView in the rtmpfromfile constructor like in the example?

@alexsafe
Copy link
Author

hi,

No, actually.

I am using compose for the project and the class looks like this:

class RtmpFileStream(
    private val context: Context,
    private val streamStore: StreamStore,
) : SurfaceView(context), ConnectChecker, VideoDecoderInterface, AudioDecoderInterface {

private var rtmpFromFile: GenericFromFile = GenericFromFile(context, this, this, this)

@alexsafe
Copy link
Author

I understand the issue now.

I was rendering using


        AndroidView(modifier = Modifier.fillMaxSize(), factory = {
            surfaceView
        })

.

Changing to

        AndroidView(modifier = Modifier.fillMaxSize(), factory = {
            openGlView
        })

and using the same openGlView in my file streaming class:
GenericFromFile(openGlView, this, this, this)

did it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants