• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

App Inventor Problem with MediaPlayer.create() when recreating with same files after mediaPlayer.release()

I have a simple media player app that works fine for a while (like each song will play about 50 times) and then starts to crash on almost all the media files (a few still work but lag really bad; there is no lag until the errors). These errors continue even after stopping the activity and reopening!

These same media files work with other media players after they quit working in mine, so there is clearly something very wrong. I have to restart my device for my Activity to be able to call MediaPlayer.create() on the files without errors again. This behavior is so obscure!

One create:
Code:
E/MediaPlayer: error (1, -38)
E/MediaPlayer: error (1, -2147483648)
E/MediaPlayer: Error (1,-38)
E/MediaPlayer: error (1, -2147479551)
E/MediaPlayer: error (1, -38)
Another:
Code:
E/MediaPlayer: error (1, -2147479551)
E/MediaPlayer: Error (1,-2147479551)
E/MediaPlayer: error (1, -38)
Yet another:
Code:
E/MediaPlayer: error (1, -38)
E/MediaPlayer: error (1, -2147479551)
E/MediaPlayer: error (1, -38)
E/MediaPlayer: Error (1,-38)

So the errors are inconsistent in order, but there are recurring numbers. One of the numbers are not in the MediaPlayer.java file for the target SDK 30, but the device I am testing is using Android 6.0.1 which I believe is SDK 23. I am not entirely sure how to find the relevent Android source. Using Google search "site:https://android.googlesource.com/ mediaplayer.java" is the best way I have found.

I did find
Code:
MEDIA_ERROR_SYSTEM = -2147483648
and
Code:
MEDIA_ERROR_UNKNOWN = 1
. I have an unknown media error from the system.

What about -2147479551? It appears to be MEDIA_ERROR_SYSTEM | 0x1001. 0x1001 does not appear in MediaPlayer.java. It is another unknown media error. What extra information was attached? What about -38?!

What could cause such a bug. I don't even know how to wrap my head around this behavior. Is MediaPlayer not releasing correctly? Am I leaking resources that don't go away when the app closes? My code is fairly simple and it appears to release everything like it is supposed to. How come a restart fixes the issue?

Here is the relevant code:
Code:
    Playlist masterPlaylist;
    public boolean surfaceCreated;
    AudioURI currentSong;
    AudioURI nextSong;
    MediaPlayer mediaPlayer;
    MediaPlayer nextMediaPlayer;
    VideoView videoView;
    final Object lock = new Object();

    MediaPlayer.OnCompletionListener onCompletionListener = new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mediaPlayer2) {
            synchronized (lock) {
                Log.i(TAG, "onCompletion started");
                currentSong = nextSong;
                mediaPlayer.release();
                mediaPlayer = nextMediaPlayer;
                if (surfaceCreated) {
                    mediaPlayer.setDisplay(videoView.getHolder());
                    mediaPlayer.start();
                }
                nextSong = masterPlaylist.next();
                executorService.submit(runnableNextMediaPlayer);
                Log.i(TAG, "onCompletion ended");
            }
        }
    };

    View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Log.i(TAG, "onClick started");
            currentSong = nextSong;
            mediaPlayer.release();
            mediaPlayer = nextMediaPlayer;
            if (surfaceCreated) {
                mediaPlayer.setDisplay(videoView.getHolder());
                mediaPlayer.start();
            }
            nextSong = masterPlaylist.next();
            executorService.submit(runnableNextMediaPlayer);
            Log.i(TAG, "onClick ended");
        }
    };

    ExecutorService executorService = Executors.newSingleThreadExecutor();

    Runnable runnableNextMediaPlayer = new Runnable() {
        @Override
        public void run() {
            synchronized (lock) {
                Log.i(TAG, "creating next MediaPlayer");
                nextMediaPlayer = MediaPlayer.create(getApplicationContext(), nextSong.getUri());                nextMediaPlayer.setVideoScalingMode(MediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
                nextMediaPlayer.setOnCompletionListener(onCompletionListener);
                Log.i(TAG, "next MediaPlayer created");
            }
        }
    };

    public void calledAtTheEndOfOnCreate() {
        videoView = findViewById(R.id.video_view);
        currentSong = masterPlaylist.next();
        mediaPlayer = MediaPlayer.create(getApplicationContext(), currentSong.getUri());
        mediaPlayer.setVideoScalingMode(MediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
        mediaPlayer.setOnCompletionListener(onCompletionListener);
        nextSong = masterPlaylist.next();
        executorService.submit(runnableNextMediaPlayer);
        videoView.getHolder().addCallback(new SurfaceHolder.Callback() {
            @Override
            public void surfaceCreated(@NonNull SurfaceHolder surfaceHolder) {
                surfaceCreated = true;
                mediaPlayer.setDisplay(surfaceHolder);
                mediaPlayer.start();
            }

            @Override
            public void surfaceChanged(@NonNull SurfaceHolder surfaceHolder, int i, int i1, int i2) {}

            @Override
            public void surfaceDestroyed(@NonNull SurfaceHolder surfaceHolder) {surfaceCreated = false;}
        });
        FloatingActionButton floatingActionButton = findViewById(R.id.fab);
        floatingActionButton.setOnClickListener(onClickListener);
    }

S20 ultra screen burn

Hi can anyone offer advice pls
I have a s20 ultra that is displaying ghost icons from my home screen
Mainly visible on a white background
Ive had the phone for 5 months
Ive had dialogue with samsung and they arranged for a mobile engineer to come to my adress and replace the screen
On arrival i got the impression he was looking for a way out of repairing it siting miniscule marks on the edges of the frame (phone has been in a case with a screen protector since new)
He took the phone to his van but returned saying there was a crack on the screen so he couldnt do anything as the 2mm ,what i thought was a scratch, was a crack and the phones warranty was invalid because of it
So the tiny damage on the screen which has nothing whatsoever to do with the original screen burn issue has invalidated my warranty on a £1400 flagship phone
Im absolutely gutted and wondered if anyone has experienced similar?
Thank you

Messages during loading

I can't find a whole lot of information about com.qti.diagservices but it seems to come from Samsung so I would guess it's a service to check the state of something on your phone. The callenhancement app or service seems to come from LG. I find it odd that they'd both be on your phone. The message you are getting means that both services have failed to load at startup.

Problem updating Android Kitkat

Since you're not sure about which ROM you tried to flash, it's probably a good thing that Odin failed like that. Flashing the wrong ROM is a good way to brick your device. It's important to only use ROMs that specifically match your model of phone, they are not interchangeable.
Go here and select the appropriate ROM, you need to not only download just the one that matches your model but also matches your county and carrier:
https://www.sammobile.com/samsung/galaxy-s4/firmware/#GT-I9505
The sammobile site is a valid source for Samsung stock ROMs. If you create an account with them, the download will be much faster. Otherwise, for non-members they intentionally limit the download bandwidth from their servers. Sammobile does claim to obtain their ROMs the manufacturers and the carriers. There are of course several other sources for Samsung ROMs, just be very judicious about where they source their ROMs from to avoid downloading a tainted one.
Regarding the Odin utility, you apparently used ver. 3.12.3 which isn't the latest version but that might not matter anyway. You might want to try using the current version, 3.14.4 but I'd suggest you just use an older version, 3.10.x. The Odin utility has backwards compatibility issues and since you're working with older hardware it might work out better using a matching version.

Keep in mind that the latest stock ROM from Samsung for your S4 is Lollipop (5.0.1) so app support will probably still to be an issue. Also, flashing a stock Samsung ROM will install a stock version of Android and a stock Recovery, so if you want to root your device you need to go through the whole rooting process again.
Otherwise, look into third-party options like Lineage OS or /e/ OS. You'll have more current versions of Android to work with and your rooted device will remain rooted.
Lineage
https://download.lineageos.org/jfltexx
https://en.wikipedia.org/wiki/LineageOS
/e/
https://doc.e.foundation/devices/
https://en.wikipedia.org/wiki//e/_(operating_system)

Screenshot notification tile exclusive to 11?

I use two different apps for screenshots, and both have the quick setting tile as an option.

Screenshot Tile (NoRoot) (Quick settings tile for screenshots) - https://f-droid.org/packages/com.github.cvzi.screenshottile

Pretty sure that is the one you would want.

The other one that I use is oart of a screen recorder app, and the latest updates have ads, so I am using an old version.

Let me know if you want that link as well.

Filter

Back
Top Bottom