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.

1 Like

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/

2 Likes

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!

1 Like

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.

2 Likes

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.

1 Like

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.

2 Likes

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.

4 Likes

Great idea, @Deluxe!

3 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.

1 Like

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.

1 Like

@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.

1 Like

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.

2 Likes

Thank you very much! Will do.

1 Like

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.

2 Likes

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

1 Like

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

2 Likes

Sure, thanks very much for your help!

2 Likes

Youā€™re welcome! Hereā€™s a slightly better version:

2 Likes

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

1 Like

@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.

1 Like