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

AUDIO_PERFORMANCE_MODE_LOW_LATENCY #1115

Open
mariam-wahba opened this issue Mar 13, 2024 · 1 comment
Open

AUDIO_PERFORMANCE_MODE_LOW_LATENCY #1115

mariam-wahba opened this issue Mar 13, 2024 · 1 comment
Labels

Comments

@mariam-wahba
Copy link

mariam-wahba commented Mar 13, 2024

Bug Report

Description of the Bug

Hello, I'm facing a problem. I'm using implementation 'com.pierfrancescosoffritti.androidyoutubeplayer:core:12.1.0' and implemented in my android app project. It works so well if i ran on virtual device android 11 and physical mobile Realme 5pro while on giada jhs558 android 11 device it is like continuous cutting while playing the video and i find this error in my console 15:12:18.255 10720-10822 AudioStreamBuilder com.xlab.andsign D build() MMAP not used because AAUDIO_PERFORMANCE_MODE_LOW_LATENCY not requested.I don't know why this happens. Can anyone help me?

Environment details

Android 11
Api level: 26 to 34

Tested devices:

  • virtual device android 11
  • Realme 5pro
  • giada jhs558 android 11

Youtube Player Library Version: implementation 'com.pierfrancescosoffritti.androidyoutubeplayer:core:12.1.0'

Steps to reproduce the bug

import static androidx.constraintlayout.helper.widget.MotionEffect.TAG;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.Toast;

import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.PlayerConstants;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.YouTubePlayer;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.listeners.AbstractYouTubePlayerListener;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView;
import com.xlab.Entities.PlayListRecord;

import androidx.annotation.NonNull;

public class YoutubeView extends FrameLayout {
private PlayListRecord playListRecord;
private final static int RETRY_DELAY = 10000;
private YoutubeErrorListener errorListener;
private boolean isError;
private boolean isInitialized;
private boolean isNetError;
private boolean isPlayStarted;
private boolean isStopped;
private boolean isTerminated;
boolean isPlayRetryQueued;
private final boolean isTraceEnabled;
private long lastPlayTime;
private String videoId;
private WebView webView;
private YouTubePlayerView youTubePlayerView;

public YoutubeView(Context context, PlayListRecord playListRecord) {
	super(context);
	isTraceEnabled = false;
	isInitialized = false;
	isNetError = false;
	isError = false;
	isPlayStarted = false;
	isStopped = false;
	isTerminated = false;
	errorListener = null;
	isPlayRetryQueued = false;
	this.playListRecord = playListRecord;
	this. videoId = playListRecord.getFileName();
	createView(context);
}

public void setErrorListener(YoutubeErrorListener errorListener) {
	this.errorListener = errorListener;
}

private void cancelRetry() {
	if (webView != null) {
		webView.removeCallbacks(playRetryRunner);
	}
}

private void hideError() {
	isError = false;
	isNetError = false;
}

private Runnable playRetryRunner = new Runnable() {
	public void run() {
		isPlayRetryQueued = false;
		play();
	}
};

private void createView(Context context) {
	youTubePlayerView = new YouTubePlayerView(context);
	addView(youTubePlayerView);

	youTubePlayerView.addYouTubePlayerListener(new AbstractYouTubePlayerListener() {
		@Override
		public void onReady(@NonNull YouTubePlayer youTubePlayer) {
			youTubePlayer.loadVideo(videoId, 0); // Load the video automatically
		}

		@Override
		public void onError(@NonNull YouTubePlayer youTubePlayer, @NonNull PlayerConstants.PlayerError error) {
			super.onError(youTubePlayer, error);
			Log.e(TAG, "YouTube player error: " + error.name());
			Toast.makeText(context, "Error loading YouTube video", Toast.LENGTH_SHORT).show();
			System.out.println(error+"");
		}
	});
}

public void destroy() {
	if (!isStopped) {
		isStopped = true;
		cancelRetry();
		if (webView != null) {
			webView.destroy();
		}
	}
	if (webView != null) {
		removeView(webView);
		webView = null;
		errorListener = null;
		playRetryRunner = null;
	}
	isTerminated = true;
}

public void start() {
	if (isStopped) {
		isStopped = false;
		if (webView != null) {
			webView.resumeTimers();
			play();
		}
	}
}

public void stop() {
	if (!isStopped) {
		isStopped = true;
		cancelRetry();
		if (webView != null) {
			webView.pauseTimers();
		}
	}
}

public void play() {
	if (!isStopped && !isPlayStarted) {
		hideError();
		if (webView != null) {
			webView.loadUrl("javascript:startVideo()");
			isPlayStarted = true;
		}
	}
}

public void seekTo(int time) {
	if (!isStopped) {
		if (webView != null) {
			webView.loadUrl("javascript:seekTo(" + time + ")");
		}
	}
}

}
public class WebAppInterface {
private YoutubeView youtubeView;
private YoutubeErrorListener errorListener;
private WebView webView;
// public WebAppInterface(YoutubeView youtubeView) {
// this.youtubeView = youtubeView;
// }
public WebAppInterface(WebView webView) {
this.webView = webView;
}

public void setErrorListener(YoutubeErrorListener errorListener) {
    this.errorListener = errorListener;
}

@JavascriptInterface
public void startVideo() {
    youtubeView.play();
}

@JavascriptInterface
public void seekTo(int time) {
    youtubeView.seekTo(time);
}

@JavascriptInterface
public void onError(String message) {
    if (errorListener != null) {
        errorListener.onError(message);
    }
}

@SuppressLint("JavascriptInterface")
@JavascriptInterface
public void onPlayerStateChange(final String state) {
    new Handler(Looper.getMainLooper()).post(new Runnable() {
        @Override
        public void run() {
            handlePlayerStateChange(state);
        }
    });
}

private void handlePlayerStateChange(String state) {
    switch (state) {
        case "paused":
            // Handle the case when the video is unexpectedly paused
            webView.loadUrl("javascript:playVideo()");
            break;
        case "ended":
            // Handle the case when the video ends
            break;
        // Add more cases if needed
    }
}

}
public interface YoutubeErrorListener {
void onError(String message);
}

Expected behavior

to work so well on all devices whether virtual or physical

Actual behavior

It works so well if i ran on virtual device android 11 while on physical android 11 device it is like continuous cutting while playing the video

Additional information

15:12:18.255 10720-10822 AudioStreamBuilder com.xlab.andsign D build() MMAP not used because AAUDIO_PERFORMANCE_MODE_LOW_LATENCY not requested.

@mariam-wahba
Copy link
Author

are there any specific configurations or recommendations for dealing with audio playback on Android 11 giada jhs 558 and ensuring low-latency performance mode is enabled?

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

1 participant