Help please: InputSeek with MP3 file (mpg123) on MacOS

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

Help please: InputSeek with MP3 file (mpg123) on MacOS

manlio.mazzon
Help please: inputSeek with MP3 file on macOS

Hello

I'm using UOS (uos_flat) successfully on the Mac, using Lazarus 2.0 and fpc 3.0.4, and for that I cannot thank you enough, so thanks, thanks and thanks :)

There's only one thing that I haven't been able to do: using inputSeek when playing MP3 files.

In fact, what happens is a little weird: after I call inputSeek, it looks like it worked, because the information returned by inputPosition reflects the change, but the actual playing of the audio file doesn't
change at all.

Here is what I do, using uos_flat:

1: Load libraries, load file, start playing:

(pseudo-code)

  uos_LoadLib(PortAudioPath, nil, Mpg123Path, nil, nil, nil)
  uos_CreatePlayer(PlayerIndex)
  InputIndex := uos_AddFromFile(PlayerIndex, pchar(filename), -1, 0, -1)
  uos_AddIntoDevOut(PlayerIndex, -1, -1, uos_InputGetSampleRate(PlayerIndex, InputIndex), -1, 0, -1, -1);
  uos_InputSetPositionEnable(PlayerIndex, InputIndex, 1); // enable tracking of position during playback
  uos_Play(PlayerIndex);

At this point the MP3 audio file starts playing.


2. I also have a TTimer event that updates the position every second:

  sec := uos_InputPositionSeconds(PlayerIndex, InputIndex) // read the current position

And this also works fine.


3.  The part that does not work is when I call Seek.

For example, in the middle of playing the audio file, if I call Seek with a parameter of 0, the audio file should start playing from the beginning.

But when I call it, for example like this...

  uos_InputSeek(PlayerIndex, InputIndex, 0);

... then 2 things happen:

A) From that moment, uos_InputPositionSeconds(...) responds as if playing had indeed restarted from the beginning, and my time indicator indeed starts showing the seconds again starting from 0, 1, 2, etc.

B) The actual audio file however, does not restart. It continues playing as if I never called seek at all.

And that's where I need your help please...

Do you have any idea of what is going on? Did I miss something or did I do something wrong?
What should I do to make Seek work?

Note 1: I'm using the 32 bit version of the mpg123 libraries.

Note 2: I looked in uos_mpg123.pas and I saw that there are 2 seek methods:

  mpg123_seek: Tmpg123_seek;
  mpg123_seek_frame: Tmpg123_seek_frame;

I saw that UOS uses the first of the two. I tried replacing it with the second, but I got the same results,
i.e. InputPosition changes after seek, but the playback does not change at all.


Any help will be extremely appreciated.

Manny Mazzon

Reply | Threaded
Open this post in threaded view
|

Re: Help please: InputSeek with MP3 file (mpg123) on MacOS

fredvs
Administrator
Hello Manny and welcome in uos forum.

I am totally sorry, I do not have a Mac to test your code.

So we will try to find a solution together.

First of all, did you try the uos SimpePlayer demo, is it working'?
SimplePlayer uses inputSeek via the scroll-bar of position.

When you run a mp3 with SimpePlayer and change the position with the scroll-bar, is it working?

> 2. I also have a TTimer event that updates the position every second:

  This is not the right way, please take a look at SimplePlayer code, do not use a timer.

IMHO, you should take a look at uos SimplePlayer code, all what you asked is there.


 
Reply | Threaded
Open this post in threaded view
|

Re: Help please: InputSeek with MP3 file (mpg123) on MacOS

manlio.mazzon
Thanks Fred, for the welcome and the fast answer :)

I was not able to compile SimplePlayer. Or rather, it was compiling, but when I started it, it was freezing.

So I created a new project from scratch, make sure that it ran on the Mac, and then I copy-and-pasted all the uos_*** methods to do things in a similar way, although not exactly in the same way. In this way I was able to play mp3 files like I mentioned.

Anyway, now that you mentioned it, I will go back to that project and I will try again to make it run without freezing, and I will let you know the result.

(I will also study the code there, so that I can tack the position without using a timer, that was a quick way for me to see what what happening, and it seemed to work. But I'll try to do it the "right" way next time :)

Thanks again Fred

Manny
Reply | Threaded
Open this post in threaded view
|

Re: Help please: InputSeek with MP3 file (mpg123) on MacOS

fredvs
Administrator
> I was not able to compile SimplePlayer. Or rather, it was compiling, but when I started it, it was freezing.

Maybe you have to check the path of uos_loadlibrary, with Mac it was set inside the mac-bundle, but you may change it according your bundle-compilation. .
Reply | Threaded
Open this post in threaded view
|

Re: Help please: InputSeek with MP3 file (mpg123) on MacOS

fredvs
Administrator
I have no Mac so if you could update SimplePlayer demo for Mac, you are welcome.

I know that with Mac you may add the libraries in bundle but maybe it is not the right way to do.
Reply | Threaded
Open this post in threaded view
|

Re: Help please: InputSeek with MP3 file (mpg123) on MacOS

manlio.mazzon
First of all, I have finally been able to run SimplePlayer on the Mac. For those who might want to try the same, I found that I had to do this:

1. In Options > Project Options> Application: enable the "Use Application Bundle..." option

2. In Options > Project Options> Application: click on [Create Application Bundle] once

3. Debugging: Either use Dwarf2 or disable it.

4. Custom options: add the following conditional defines:
-ddynlink
-dnogdiplus
-dportaudio
-dmpg123
-usecthreads

After figuring out all of the above I was able to compile and run the demo.

(BTW I also learned how to get the playing position in real time, without TTimer (using uos_LoopProcIn(...) as a callback method), thanks for that tip.)

The problem with changing position, however, remained the same even on SimplePlayer as it was in my own test app.

in SimplePlayer, when I change the TrackBar2 to a new position:

1) The music continues playing without any change

2) The position of TrackBar2 changes as if the playing position had changed -- so it is now out of sync with the audio.

In fact, if I move TrackBar2 forward in time, the time shown on "lposition.caption" will go even beyond the end of the audio. For example, if the audio has just begun, and I move the Trackbar near the end of the audio, the time shown will soon reach the end of the audio and go beyond it, even though the audio itself is still in the initial portion.

I think this looks like the problem is not in your code, but it is in the external library, LibMpg123-32.dylib

I don't know if you have the source code for that, or who might be willing and able to look into that?

And I think it is a bug rather than a limitation -- I mean, if the library was not supposed to seek/reposition MP3 files, at least it should not change the runtime position. If it accepts the new runtime position, and returns that new position in the callback method, then it looks like it is supposed to be able to do that seek operation after all.

Unfortunately for me, this is quite an important feature for my program -- an mp3 player that cannot reposition the track will not make my users very happy. Otherwise UOS is perfect in every way.

Any good suggestion or fix would be really appreciated...

Thanks

Manny





Thanks

Manny


Reply | Threaded
Open this post in threaded view
|

Re: Help please: InputSeek with MP3 file (mpg123) on MacOS

fredvs
Administrator
Hello.

Could you try this, with your earlier code, add at end:

  uos_LoadLib(PortAudioPath, nil, Mpg123Path, nil, nil, nil)
  uos_CreatePlayer(PlayerIndex)
  InputIndex := uos_AddFromFile(PlayerIndex, pchar(filename), -1, 0, -1)
  uos_AddIntoDevOut(PlayerIndex, -1, -1, uos_InputGetSampleRate(PlayerIndex, InputIndex), -1, 0, -1, -1);
  uos_InputSetPositionEnable(PlayerIndex, InputIndex, 1); // enable tracking of position during playback
  uos_Play(PlayerIndex);

  // add this
  uos_InputSeek(PlayerIndex1, InputIndex, 30000);

When you start playing, is it changing position?

I just retested for Linux, FreeBSD and Windows, it is ok.

Maybe LibMpg123-32.dylib is corrupted.
You may try to find a other in intenet or compile the source (see in uos credits.txt)

Thanks for your tips about Mac-compilation, I did create a topic with it.
Reply | Threaded
Open this post in threaded view
|

Re: Help please: InputSeek with MP3 file (mpg123) on MacOS

fredvs
Administrator
The name of the library for Mac is libmpg123.0.dylib, there are a lot pre-compiled on the web, maybe one will work.
Reply | Threaded
Open this post in threaded view
|

Re: Help please: InputSeek with MP3 file (mpg123) on MacOS

manlio.mazzon
In reply to this post by fredvs
Like you suggested, I just tried adding uos_InputSeek right after uos_Play, and it has no effect of any kind.

Again, if I call uos_InputSeek while the audio is already playing, then at least the Position gets changed. But if I call it immediately, like you indicated, there is no effect of any kind.

I will now try to find some other online copy of that library, and try with that. It really looks like the problem is in the library, not in your code. Your code simply loads the external method from the library, and then calls it.  Let's see if I can find a library that works for me... I'll let you know what I find.

Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: Help please: InputSeek with MP3 file (mpg123) on MacOS

fredvs
Administrator
>  But if I call it immediately, like you indicated, there is no effect of any kind.

Maybe without any help, but did you try using "application.processmessages" before and after seek, maybe Mac needs it?
Reply | Threaded
Open this post in threaded view
|

Re: Help please: InputSeek with MP3 file (mpg123) on MacOS

manlio.mazzon
Yes I tried Application.ProcessMessages before and after, no effect.

I also tried to call uos_Pause before the seek, and uos_RePlay after the seek, no effect.

I looked online for libmpg123.0.dylib files. I found one, tried to download and replace LibMpg123-32.dylib, but I got an error, didn't load. (Perhaps 64 vs 32 bit)

I'm still searching, and I see that file mentioned in several places, but I cannot find any other download link for a different version. If you have any idea of where to find another version of libmpg123.0.dylib / LibMpg123-32.dylib please let me know

Thanks!

(P.S. I created another ticket about a different issue regarding @ShowPosition but that's a minor issue)
Reply | Threaded
Open this post in threaded view
|

Re: Help please: InputSeek with MP3 file (mpg123) on MacOS

fredvs
Administrator
If you are courageous, you may try to compile mpg123 source.
Reply | Threaded
Open this post in threaded view
|

Re: Help please: InputSeek with MP3 file (mpg123) on MacOS

fredvs
Administrator
Maybe if you install mpg123 application, it will add also the library in the directory.
http://macappstore.org/mpg123/
Reply | Threaded
Open this post in threaded view
|

Re: Help please: InputSeek with MP3 file (mpg123) on MacOS

manlio.mazzon
OK, finally I managed to make it work :)

In the end I had to use the 64 bit compiler and a different dylib file that I downloaded online.

Here are all the details if someone needs to do the same:

1. Originally I used UOS + mpg123 (32 bit) on the Mac to play mP3 files. It played files OK, but repositioning didn't work.

2. Eventually figured that the problem is not with the UOS code but with the library, LibMpg123-32.dylib

3. I tried replacing that library with another one I found online, without success.

4. I decided to try the 64 bit version. Unfortunately Lazarus for the Mac only comes in 32-bit flavour. So I had to recompile it, using x86_64 as the target CPU. I also had to replace Carbon LCL widgetset with Cocoa. (Carbon only supports 32 bit. Cocoa doesn't work quite as well on Lzarus but it supports 64 bit). Followed the instructions on the Lazarus / Mac wiki and managed to recompile Lazarus for the Mac in 64 bits.

5. I recompiled the demo in 64 bits. (Again, had to make sure Target CPU is x86_64, LCLWidgetSet is Cocoa, and any other adjustment that may be necessary when moving to 64 bits).

6. Again the MP3 played fine, but repositioning (seek) still didn't work.

7. I looked online for other versions of the LibMpg123-64.dylib file, whose common name on the Mac is
libmpg123.0.dylib and I found this on github:

  https://github.com/JetForMe/podtique/blob/master/Xcode/libmpg123.0.dylib

8. I downloaded it, used it to replace LibMpg123-64.dylib in UOS, and finally everything works, including repositioning!

Bottom line:

I think there's something wrong with the Mac version of the LibMpg123-XX.dylib included in UOS. The "seek" function in both the 32 and 64 bit versions doesn't work. (Everything else works fine, as far as I can tell).

Using the above 64-bit library fortunately worked for me. However I could not find a 32-bit library that worked too.

Many many thanks to fredvs -- your kind and fast answers kept me going, and your tips about trying other versions of the library pointed me toward a solution that worked :)

All the best to everyone

M
Reply | Threaded
Open this post in threaded view
|

Re: Help please: InputSeek with MP3 file (mpg123) on MacOS

fredvs
Administrator
Yep, I am very happy that it works!

It was a big battle but you win, congrats.

About the no-working dylib of uos, of course you are welcome to share the good one.

Fre;D