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

Background Streaming #28

Closed
rocxteady opened this issue Jun 7, 2014 · 15 comments
Closed

Background Streaming #28

rocxteady opened this issue Jun 7, 2014 · 15 comments
Labels

Comments

@rocxteady
Copy link

Hello.

I am using IjkPlayer for audio streaming and I want to be able to stream in the background. I have found all the methods which paused the stream when app goes to background but the app still pauses streaming when I locked the device.

The interesting thing is the app only pauses when the device's light is off. When I turn the light on but keep locked the devices, the app continues streaming. When I turn the light of by pressing power button it pauses streaming again. (I think it is called "Sleep Mode")

Can you help? Thanks.

@bbcallen
Copy link
Contributor

Look into VideoView.java

        public void surfaceDestroyed(SurfaceHolder holder) {
            mSurfaceHolder = null;
            if (mMediaController != null)
                mMediaController.hide();
            if (mCurrentState != STATE_SUSPEND)
                release(true);
        }

@rocxteady
Copy link
Author

I am sorry. My question is for iOS.

@bbcallen
Copy link
Contributor

Look into IJKFFMoviePlayerController.m

- (void)applicationWillResignActive
{
    NSLog(@"IJKFFMoviePlayerController:applicationWillResignActive: %d", (int)[UIApplication sharedApplication].applicationState);
    dispatch_async(dispatch_get_main_queue(), ^{
        [self pause];
    });
}

- (void)applicationDidEnterBackground
{
    NSLog(@"IJKFFMoviePlayerController:applicationDidEnterBackground: %d", (int)[UIApplication sharedApplication].applicationState);
    dispatch_async(dispatch_get_main_queue(), ^{
        [self pause];
    });
}

- (void)applicationWillTerminate
{
    NSLog(@"IJKFFMoviePlayerController:applicationWillTerminate: %d", (int)[UIApplication sharedApplication].applicationState);
    dispatch_async(dispatch_get_main_queue(), ^{
        [self pause];
    });
}

OpenGL ES must be paused in background, and background audio session need extra work.
I just pause whole player for the convenience.

You have to handle application state change in both video output and audio output

@rocxteady
Copy link
Author

I have already commented these pause linea. What else do I need to do?

@bbcallen
Copy link
Contributor

Than you should implement them in IJKSDLGLView.m and IJKSDLAudioQueueController.m properly.

After that, only aout and vout are paused, and read_thread works on.

@rocxteady
Copy link
Author

I am not using IJKSDLGLView. What do I specificly need to do in IJKSDLAudioQueueController.m?

@bbcallen
Copy link
Contributor

Just call pause(). Not sure if there is any thread issue

@rocxteady
Copy link
Author

Call pause? I don't want to pause streaming. I want to continue streaming on the background. My problem is that it pauses steaming when phone goes into sleep mode.

@bbcallen
Copy link
Contributor

I mean call [IJKSDLAudioQueueController pause], It only pause the playing, but not stream IO.

If you mean play in background, it would need more work to do.
Try search AudioSession, background

@rocxteady
Copy link
Author

Normally, while HLS streaming I am doing this:

NSError *setCategoryErr = nil;
NSError *activationErr = nil;
[[AVAudioSession sharedInstance] setDelegate: self];
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:&setCategoryErr];

And I also set the proper value in the info.plist

And it plays fine in the background and the sleep mode.

But while using your library, these settings are not enough to play in sleep mode.

@bbcallen
Copy link
Contributor

It's not the settings' problem, but ijkplayer's problem.

Strictly speaking, audio output is not implemented correctly in ijkplayer.
The IJKSDLAudioQueueController should handle so called 'sleep mode' and
audio session properly, to support background playing.

@rocxteady
Copy link
Author

So what should I do now? Should I wait for an update?

@bbcallen
Copy link
Contributor

Sorry, I don't known how, and don't have any plan to do that in weeks.
I suggest find other iOS audio play libs, and try make them/it working together with ijkplayer.

@bbcallen bbcallen added the bug label Jun 20, 2014
@rocxteady
Copy link
Author

Thank you anyway. It is a good library. And I don't know any iOS library that can play rtmp streams. I know some but they suck. :)

@bbcallen
Copy link
Contributor

I mean find libs using CoreAudio and support background play, to see how they deal with this issue, and integrate it into ijkplayer.

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

No branches or pull requests

2 participants