How to manipulate audio position

Hey Thunkers!

In my app, I have an audio-file playing screen, which will play audio files the user has uploaded. I want to know if:
i) Is there any way to display the length of the audio file?
ii) Is it possible to have a progress bar that can set the position of the audio file when dragged?

iii) Display how much of the song has finished?
iv) Also, is there any way to set the image of m data viewer list back to the play icon once the song has finished? I know how to change the image of a certain DVL part, but it’s not changing once the song has finished playing.
This is my code:


Edit: It worked only on the phone during Live Test, that was the issue

@domhnallohanlon This audio manipulation is something I would dearly want with the sound component, along with finding the length of the file, because I am not pre-defining the audio clips.
Any ideas on how to do this?

Thanks.

You can only do this in a very limited way and only if the duration of the media file is known in advance. Timers would come in handy inthis scenario. If you have an Android device you can check my DeluxeTube tech-demo app which imements just that for its playlist mode. Check the description and limitations in the post as well.

http://community.thunkable.com/t/deluxetube-a-youtube-video-player-tech-demo/

1 Like

Hi @Deluxe, thanks for the reply!

The media file is definitely not know in advance as these audio clips are stuff that the user has recorded within the app.

How can I use timers to figure out the maximum time? Any help would be appreciated if you have tried this.

Wow! I read your post on DeluxeTube, and I found it quite impressive. I do have an Android device, and will definitely check it out. Would it be possible for you to make it open-source, because I would love to take a look at the code.
Thanks!

The timer comes in handy when you know the duration of the media file and you need to advance to the next media file. This works by setting the timer duration equal to the length of the media file (i.e. in seconds) plus 2 or 3 seconds in case it is streamed for buffering delays etc. and then load the next media file when the timer fires. Of course, if the user moves back and forth in the media file then the timer sync will be off and this will not work. Since we don’t have the necessary controlls, this is the best I could come up with.

1 Like

Thanks @Deluxe! But in this case, I don’t know the length of the media file because the user has recorded the files. Also, there’s no need to load the next file, because the user has to click on files to play them(they are all displayed in a screen. Yes, it’s confusing because we can’t predict what the user will do. These controls(length of sound file, from sound1 set position, from sound1 call get elapsed) would be very helpful and would make it so much easier.
Thank you for your help.

I’m going to guess you could determine the audio file duration by uploading it to cloudinary and then using the API to retrieve the duration.

But it’s a guess because I haven’t found that feature in their documentation yet. It would also be a bit slow to upload everything (even temporarily) to cloudinary if you don’t otherwise need to store it in the cloud.

1 Like

Well… there is a way. Get the seconds since 1970 before and after taking the video (EDIT: or audio), subtract, store in a local table for reference when later viewing the video in the app.

Tested it, works like a charm.

EDIT: Ok I see the original question is related to audio recorded by the user through the app. In this case, the principle is the same.

3 Likes

Great idea, @Deluxe!

2 Likes

Hi @tatiang that’s a great idea! How can I view the JSON response of the media_db, in order to retrieve max length? Since it’s a default component in Thunkable, there’s no need to have the JSON. How do I do this? Thanks.

Wow @Deluxe ! That is an amazing idea! Will definitely try that. I should set the max length of the slider to the length of the song to make the progress bar, right? Also, how do I move the slider in order to show the completed part of the song?
Thanks.

@Deluxe, I tried your code(used variables instead of labels to save start time and end time), and this is my code:


But when I tested it, I got -47.31 as the recording time. What have I done wrong?
**Edit: I fixed it using in text replace - with **

There’s also another problem. I’m unable to get the code to narrow itself down to minutes and seconds if more than 60. I got 1.87 in my time, even though I coded this:


Any idea on how to round it to minutes:seconds without breaking any rules of time😀

Thanks.

The duration is going to be [seconds since 1970] - [app variable start seconds since 1970]. There’s no need for an [app variable end seconds since 1970] block.

1 Like

Thank you very much! Will do.

Here’s how I would calculate minutes and seconds:

It’s not perfect… for example, I didn’t “pad” the values. So 2 minutes and 5 seconds will appear as 2:5, not 2:05. You also probably need to round the duration before you use it in the expressions below it.

To test it out, just set [app variable duration] to an integer such as 210. You can do that right below the set [app variable duration] block.

1 Like

Thanks a lot. And if the time is less than a minute?

I think it should still work for times less than a minute. Try it and let me know!

1 Like

Sure, thanks very much for your help!

1 Like

You’re welcome! Here’s a slightly better version:

1 Like

Wow! That is perfect! Am trying it out right now, and will tell you immediately.

@tatiang, I received image for a

second recording. I started a timer on my phone as soon as I pressed the RECORD button, so I have an accurate time.