# How to manipulate audio position

**URL:** <https://community.thunkable.com/t/how-to-manipulate-audio-position/1078891>\
**Category:** Questions about Thunkable X\
**Created:** [February 2, 2021, 5:31am UTC](https://community.thunkable.com/t/how-to-manipulate-audio-position/1078891 "2021-02-02T05:31:57Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [February 2, 2021, 5:31am UTC](https://community.thunkable.com/t/how-to-manipulate-audio-position/1078891/1 "2021-02-02T05:31:57Z")

</div>

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?  
[![](https://us.v-cdn.net/6030293/uploads/6EY0OB4TJY3J/progress-png.png) ](https://us.v-cdn.net/6030293/uploads/6EY0OB4TJY3J/progress-png.png)  
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:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/e/be84369e1129657656719543b9e81eb98dd923fb.png)  
**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.

---

<div class="post-metadata">

**Author:** ![Deluxe](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/deluxe/32/30016_2.png) [@Deluxe](https://community.thunkable.com/u/Deluxe)\
**Post date:** [February 2, 2021, 1:35pm UTC](https://community.thunkable.com/t/how-to-manipulate-audio-position/1078891/2 "2021-02-02T13:35:44Z")

</div>

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/](http://community.thunkable.com/t/deluxetube-a-youtube-video-player-tech-demo/)

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [February 2, 2021, 2:45pm UTC](https://community.thunkable.com/t/how-to-manipulate-audio-position/1078891/3 "2021-02-02T14:45:00Z")

</div>

Hi @Deluxe, thanks for the reply!

> [@Deluxe](#):
>
> only if the duration of the media file is known in advance.

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

> [@Deluxe](#):
>
> Timers would come in handy inthis scenario.

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

> [@Deluxe](#):
>
> If you have an Android device you can check my DeluxeTube tech-demo app which imements just that for its playlist mode.

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!

---

<div class="post-metadata">

**Author:** ![Deluxe](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/deluxe/32/30016_2.png) [@Deluxe](https://community.thunkable.com/u/Deluxe)\
**Post date:** [February 2, 2021, 3:06pm UTC](https://community.thunkable.com/t/how-to-manipulate-audio-position/1078891/4 "2021-02-02T15:06:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [February 2, 2021, 3:49pm UTC](https://community.thunkable.com/t/how-to-manipulate-audio-position/1078891/5 "2021-02-02T15:49:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [February 2, 2021, 7:03pm UTC](https://community.thunkable.com/t/how-to-manipulate-audio-position/1078891/6 "2021-02-02T19:03:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Deluxe](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/deluxe/32/30016_2.png) [@Deluxe](https://community.thunkable.com/u/Deluxe)\
**Post date:** [February 2, 2021, 10:21pm UTC](https://community.thunkable.com/t/how-to-manipulate-audio-position/1078891/7 "2021-02-02T22:21:34Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/3/2/322680dc9eff1f38e2f436d5634da23ab1db7109.png)

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.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [February 3, 2021, 12:40am UTC](https://community.thunkable.com/t/how-to-manipulate-audio-position/1078891/8 "2021-02-03T00:40:12Z")

</div>

Great idea, @Deluxe!

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [February 3, 2021, 3:31am UTC](https://community.thunkable.com/t/how-to-manipulate-audio-position/1078891/9 "2021-02-03T03:31:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [February 3, 2021, 3:34am UTC](https://community.thunkable.com/t/how-to-manipulate-audio-position/1078891/10 "2021-02-03T03:34:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [February 3, 2021, 3:45am UTC](https://community.thunkable.com/t/how-to-manipulate-audio-position/1078891/11 "2021-02-03T03:45:08Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/8/b8b51f7d3d8973b5fe0c8241cc6882f61bd2a3d5.png)  
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:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/7/f750b9a40596ed1b36ee787047fd0e5d35871a32.png)  
Any idea on how to round it to minutes:seconds without breaking any rules of time😀

Thanks.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [February 3, 2021, 4:11am UTC](https://community.thunkable.com/t/how-to-manipulate-audio-position/1078891/12 "2021-02-03T04:11:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [February 3, 2021, 4:13am UTC](https://community.thunkable.com/t/how-to-manipulate-audio-position/1078891/13 "2021-02-03T04:13:47Z")

</div>

Thank you very much! Will do.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [February 3, 2021, 4:18am UTC](https://community.thunkable.com/t/how-to-manipulate-audio-position/1078891/14 "2021-02-03T04:18:54Z")

</div>

Here’s how I would calculate minutes and seconds:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/1/910bb0a230baf9235acb0e094ee7ae89bc738b46.png)

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.

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [February 3, 2021, 4:19am UTC](https://community.thunkable.com/t/how-to-manipulate-audio-position/1078891/15 "2021-02-03T04:19:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [February 3, 2021, 4:20am UTC](https://community.thunkable.com/t/how-to-manipulate-audio-position/1078891/16 "2021-02-03T04:20:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [February 3, 2021, 4:21am UTC](https://community.thunkable.com/t/how-to-manipulate-audio-position/1078891/17 "2021-02-03T04:21:42Z")

</div>

Sure, thanks very much for your help!

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [February 3, 2021, 4:25am UTC](https://community.thunkable.com/t/how-to-manipulate-audio-position/1078891/18 "2021-02-03T04:25:10Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/f/9f2f6e99eed49dbfbfc567cdfcfed9f57ecaa93d.png)

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [February 3, 2021, 4:26am UTC](https://community.thunkable.com/t/how-to-manipulate-audio-position/1078891/19 "2021-02-03T04:26:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [February 3, 2021, 4:31am UTC](https://community.thunkable.com/t/how-to-manipulate-audio-position/1078891/20 "2021-02-03T04:31:32Z")

</div>

@tatiang, I received ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/3/3/33bdd830dadaa31fb60980f9af1c678ca0b1de17.png) for a

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/a/9/a97138143617bd208296a36fb47aec118e8c8b20.jpeg) second recording. I started a timer on my phone as soon as I pressed the RECORD button, so I have an accurate time.

[Next page](https://community.thunkable.com/t/how-to-manipulate-audio-position/1078891.md?page=2)
