Android Question MediaPlayerStream - SeekTo and getCurrentPosition

shashkiranr

Active Member
Licensed User
Hi ,

I am trying to acess the methods SeekTo and getCurrentPosition of MediaPlayerStream using reflection library but im getting no such methods found. im using the below code.

B4X:
r.RunPublicmethod("getCurrentPosition",Array As Object(""),Array As String("java.lang.int"))


r.RunPublicmethod("seekTo ",Array As Object(position), Array As String("java.lang.int"))

Kindly let me know which reflection method i should use.

Regards,
SK
 

GuyBooth

Active Member
Licensed User
Erel

You know what, I was not able to use the JavaObject method but I included the position property into the audio.xml file in and fired the seekbar code from your MediaPlayer Library. And It works perfectly, It shows the total duration, current position and changing position when you move the seekbar.
Shahid, I'm wondering if in fact you are streaming the audio. We know that the seekbar code works fine with MediaPlayer, and I am using that. What it doesn't work with is the MediaPlayerStream. I tried modifying the Audio.xml and with the MediaPlayerStream object I still get an "Unkown Member: Position" error when I call MP.Position.
So perhaps you are inadvertantly still using the Media Player, and not streaming. Unless I have done something wrong in the xml. How does the Audio.xml file link to the MediaPlayerStream library?
 
Upvote 0

Shahid Saeed

Active Member
Licensed User
Shahid, I'm wondering if in fact you are streaming the audio. We know that the seekbar code works fine with MediaPlayer, and I am using that. What it doesn't work with is the MediaPlayerStream. I tried modifying the Audio.xml and with the MediaPlayerStream object I still get an "Unkown Member: Position" error when I call MP.Position.
So perhaps you are inadvertantly still using the Media Player, and not streaming. Unless I have done something wrong in the xml. How does the Audio.xml file link to the MediaPlayerStream library?
@GuyBooth you just need to update the audio.xml file located in to the default media library (B4A installation location). Once done right click on lib tab in B4A and refresh. Now you will be able to see Position as an member object when you type.
B4X:
mp.Position
 
Upvote 0

Shahid Saeed

Active Member
Licensed User
Shahid, IsPaused is a special keyword - it is used in reference to Activities and services to see if they are still running or not. So you cannot use
it to determine the paused state of the player.

I use a routine somewhat like this, with PlayerPaused as a global variable:
B4X:
    If MP.IsPlaying Then
        MP.Pause
        ' It was playing and now it is paused:
        PlayerPaused = True
    End If
@GuyBooth I have tried the same way but I guess when combining it with IsPlaying giving the same effect like if I use as IsPlaying or not playing. Because when it is playing the play pause enables. But when psused play button is disabled which is infact in the state of not playing and is paused state it should enables the play button.

Why I need to do is because if I keep the play button enabled by default and playback is not loaded yet when user press it it gives unknown media error and skips to next track.
 
Upvote 0

GuyBooth

Active Member
Licensed User
@GuyBooth you just need to update the audio.xml file located in to the default media library (B4A installation location). Once done right click on lib tab in B4A and refresh. Now you will be able to see Position as an member object when you type.
B4X:
mp.Position
I tried this Shahid but the property does not appear in the MediaPlayerStream object - only in the MediaPlayer object, which has the property without modifying the xml file.
 
Upvote 0

Shahid Saeed

Active Member
Licensed User
I tried this Shahid but the property does not appear in the MediaPlayerStream object - only in the MediaPlayer object, which has the property without modifying the xml file.
If you will not add Position Property to MediaPlayerStream section it won't show, you must have to modify the audio.xml file. I have attached my modified audio.xml file. you can update the file in this location: C:\Program Files (x86)\Anywhere Software\Basic4android\Libraries
 

Attachments

  • Audio.zip
    5.1 KB · Views: 200
Upvote 0

GuyBooth

Active Member
Licensed User
If you will not add Position Property to MediaPlayerStream section it won't show, you must have to modify the audio.xml file. I have attached my modified audio.xml file. you can update the file in this location: C:\Program Files (x86)\Anywhere Software\Basic4android\Libraries
Sorry Shahid, but that didn't work on my system.

How are you declaring your MediaPlayerStream object (mp)?
 
Upvote 0

Shahid Saeed

Active Member
Licensed User
Sorry Shahid, but that didn't work on my system.

How are you declaring your MediaPlayerStream object (mp)?

I am outside now I will update you with complete code in few hours.

But it is:

B4X:
Dim mp As MediaPlayerStream

Maybe you are doing something wrong. Can you tell me step by step what are you doing.

You should do as follow:
1- Close B4A Application
2- Go to the installation folder of B4A App
3- Go to Library Folder
4- Replace the Audio.xml file I provided previously. In case you don't want to replace rename the current file and copy mine as well.
5- Open B4A App and load your project.
6- just call mp.Position and it should be available now.

I will try to create a small tutorial for that with complete project source.
 
Last edited:
Upvote 0

GuyBooth

Active Member
Licensed User
Ok Shahid, I think I have it working :)

For a variety of reasons, I kept hitting the wrong combination of files and modifications. You might want to check the xml file you posted - I think in fact it is the original file, not the modified one. I went back to your earlier post and modified my own xml file again and have it working with a flac file streaming from my NAS.

I will do some more testing to confirm that everything is working as it should.

Erel - is there something that can be done with the published version of b4a to incorporate this?
 
Upvote 0

dualznz

Member
Licensed User
i to have tried adding mp.Position to mediaplayerstream after changing the Audio.xml file but the library still thinks that mp.Position does not exist with MediaPlayerStream.

Update:
i modified the xml file manually and now its working like a charm
cheers
 
Last edited:
Upvote 0
Top