Jump to content
  • Advertisement
Sign in to follow this  

Unity Custom Mobile Audio Player for Unity3d

This topic is 1338 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello code veterans, Im currently working on a project that requires the use of an Audio player in unity3d. Since Im doing this audio player from scratch I have the Play, Pause, Stop and the seekbar working perfectly. (seekbar took an entire day breaking my head off on trying to write a formula to calculate the time and seekbar width accurately).


However since this is on mobile, the user has to be able to move the bar circle to the desired time the user wants to listen to. Kind of like youtube where you want to skip to your favorite part of a video by moving the circle. Ive been stuck on this for around 1 1/4 day's and Ive been dead stuck, only making tiny progress. Heres my Bar circle code as well as a bit of my play pause code.



#pragma strict

import PlayPause;
var script : PlayPause;
var sensisitivity : float = 300.0f;

var timeCaptured : float = 0.0f;
var totalTimey : float = 0.0f;

var minX : float = 114.5f;
var maxX : float = 0.0f;

function LateUpdate () {
		timeCaptured = script.capturedTime;
		totalTimey = script.gameObject.audio.clip.length; //using a varible = the length of the audioclip (which is read only)
		totalTimey -= script.gameObject.audio.time; //when the audio starts, the time subtracts the length. which makes it count down.
		script.gameObject.audio.time = timeCaptured;
		var h : float = sensisitivity * Input.GetAxis("Mouse X");
		gameObject.guiTexture.pixelInset.x += h;
		script.capturedTime = (script.gameObject.audio.time * script.gameObject.guiTexture.pixelInset.x)/script.gameObject.audio.clip.length;

and a bit from the playpause

private var paused = false;

public var capturedTime : float = 0;
private var totalTime : float = 0;
private var clickChecker : float = 0;
private var seekbarTime : float = 0;

function Start () {
	gameObject.audio.clip = clip; //insert the clip to the audio source
	play.guiTexture.enabled = true; //play gui
	pause.guiTexture.enabled = false; //stop gui
	seekbar.guiTexture.pixelInset.width = seekbarLimit; //for visual purposes

function LateUpdate () {
	totalTime = gameObject.audio.clip.length; //equal the varible to the length of the audioclip (which is read only)
	totalTime -= gameObject.audio.time; //when the audio starts, the time subtracts the length. which makes it count down.
	audioTime.guiText.text = totalTime.ToString(); //just for displaying text
	seekbarTime = gameObject.audio.time;
	if(paused == false){
		capturedTime = gameObject.audio.time; //for saving audio time
	else if(paused){
		capturedTime = capturedTime; //when audio is paused, catch the time
	seekbar.guiTexture.pixelInset.width = (gameObject.audio.time * seekbarLimit)/gameObject.audio.clip.length; //calculating the time for the seekbar ACCURATLY
	seekbar.guiTexture.pixelInset.width = Mathf.Clamp(seekbar.guiTexture.pixelInset.width, 0.0f, seekbarLimit); //clamp the seekbar so it doesnt go over its boundarys

Please excuse my lousy and messy coding but can anyone suggest or think of a solution that best helps what I'm currently trying to do please and thank you :)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!