fix the seek functionality it's not working I have two raw images seekerline is on top and waveformbar is on bottom in my current setup (correct me on that if I did wrong by doing that) also make clear public voids for play pause and stop so I may link those to buttons, provide entire script ty.

using System;
using System.IO;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

[RequireComponent(typeof(AudioSource))]
public class WaveformPlayer : MonoBehaviour, IPointerDownHandler, IDragHandler
{
    [Header("UI Elements")]
    public RawImage baseWaveformImage;
    public RawImage seekWaveformImage;

    [Header("Colors")]
    public Color baseColor = Color.gray;
    public Color seekColor = Color.cyan;

    [Header("Audio")]
    public string wavFilePath;

    public AudioSource audioSource;
    private AudioClip audioClip;

    private Texture2D baseTexture;
    private Texture2D seekTexture;

    private int textureWidth = 1024;
    private int textureHeight = 128;

    private float[] audioSamples; // full audio samples

    private bool isLoaded = false;

    private void Awake()
    {
        audioSource = GetComponent<AudioSource>();
    }

    // Call this to load a WAV file manually or on Start
    public void LoadWavFile(string path)
    {
        if (audioSource.isPlaying)
            audioSource.Stop();

        wavFilePath = path;
        // Load WAV samples + frequency
        try
        {
            audioSamples = null;

            AudioClip clip = LoadWav(path, out float[] samples);
            if (clip == null || samples == null || samples.Length == 0)
            {
                Debug.LogError("Failed to load WAV file or audio data.");
                isLoaded = false;
                return;
            }

            audioClip = clip;
            audioSamples = samples;

            audioSource.clip = audioClip;
            audioSource.playOnAwake = false;

            GenerateWaveformTextures();

            isLoaded = true;
        }
        catch (Exception e)
        {
            Debug.LogError("Exception loading WAV: " + e.Message);
            isLoaded = false;
        }
    }

    private void GenerateWaveformTextures()
    {
        // Dispose old textures
        if (baseTexture != null) Destroy(baseTexture);
        if (seekTexture != null) Destroy(seekTexture);

        baseTexture = new Texture2D(textureWidth, textureHeight, TextureFormat.RGBA32, false);
        seekTexture = new Texture2D(textureWidth, textureHeight, TextureFormat.RGBA32, false);

        baseTexture.wrapMode = TextureWrapMode.Clamp;
        seekTexture.wrapMode = TextureWrapMode.Clamp;

        // Draw waveform on textures
        DrawWaveformTexture(audioSamples, baseTexture, baseColor);
        DrawWaveformTexture(audioSamples, seekTexture, seekColor);

        baseTexture.Apply();
        seekTexture.Apply();

        baseWaveformImage.texture = baseTexture;
        seekWaveformImage.texture = seekTexture;

        // Match seek overlay size to base waveform
        seekWaveformImage.rectTransform.sizeDelta = baseWaveformImage.rectTransform.sizeDelta;
        seekWaveformImage.rectTransform.position = baseWaveformImage.rectTransform.position;
    }

    private void DrawWaveformTexture(float[] samples, Texture2D tex, Color color)
    {
        // Clear texture first
        Color clearColor = new Color(color.r, color.g, color.b, 0f);
        Color[] clearColors = new Color[textureWidth * textureHeight];
        for (int i = 0; i < clearColors.Length; i++) clearColors[i] = clearColor;
        tex.SetPixels(clearColors);

        int packSize = samples.Length / textureWidth;
        if (packSize <= 0) packSize = 1;

        for (int x = 0; x < textureWidth; x++)
        {
            int startSample = x * packSize;
            int endSample = Mathf.Min(startSample + packSize, samples.Length);

            float max = 0f;
            for (int i = startSample; i < endSample; i++)
            {
                float val = Mathf.Abs(samples[i]);
                if (val > max) max = val;
            }

            int height = (int)(max * (textureHeight / 2f));

            // Draw vertical line centered vertically
            int center = textureHeight / 2;
            for (int yOffset = -height; yOffset <= height; yOffset++)
            {
                int y = center + yOffset;
                if (y >= 0 && y < textureHeight)
                {
                    tex.SetPixel(x, y, color);
                }
            }
        }
    }

    private void Update()
    {
        if (!isLoaded || !audioSource.clip) return;

        // Update seek overlay to current playback time
        float normalizedTime = audioSource.time / audioSource.clip.length;
        UpdateSeekOverlay(normalizedTime);
    }

    private void UpdateSeekOverlay(float normalizedTime)
    {
        int seekWidth = (int)(normalizedTime * textureWidth);
        seekWidth = Mathf.Clamp(seekWidth, 0, textureWidth);

        Color[] pixels = seekTexture.GetPixels();

        for (int x = 0; x < textureWidth; x++)
        {
            for (int y = 0; y < textureHeight; y++)
            {
                int i = y * textureWidth + x;
                Color pixel = pixels[i];
                if (pixel.a > 0f)
                {
                    pixels[i].a = (x < seekWidth) ? 1f : 0f;
                }
            }
        }

        seekTexture.SetPixels(pixels);
        seekTexture.Apply();
    }

    // Button Mappable Methods
    public void PlayAudio()
    {
        if (isLoaded)
        {
            audioSource.Play();
        }
    }

    public void PauseAudio()
    {
        if (audioSource.isPlaying)
        {
            audioSource.Pause();
        }
    }

    public void StopAudio()
    {
        audioSource.Stop();
        audioSource.time = 0f;
    }

    // Seek on UI interaction
    public void OnPointerDown(PointerEventData eventData)
    {
        TrySeek(eventData);
    }

    public void OnDrag(PointerEventData eventData)
    {
        TrySeek(eventData);
    }

    private void TrySeek(PointerEventData eventData)
    {
        if (!isLoaded) return;

        RectTransform rt = baseWaveformImage.rectTransform;

        Vector2 localPoint;
        if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rt, eventData.position, eventData.pressEventCamera, out localPoint))
            return;

        float pct = Mathf.InverseLerp(rt.rect.xMin, rt.rect.xMax, localPoint.x);
        pct = Mathf.Clamp01(pct);

        if (audioSource.clip)
        {
            audioSource.time = pct * audioSource.clip.length;
            if (!audioSource.isPlaying)
                audioSource.Play();
        }
    }

    #region WAV Loading Helper

    /// <summary>
    /// Loads a WAV file from a path, returns AudioClip & float[] samples.
    /// Supports 8, 16, and 32-bit (float PCM) WAVs.
    /// </summary>
    /// <param name="filePath">Full path to wav file</param>
    /// <param name="samples">Output float array of samples</param>
    /// <returns>AudioClip</returns>
    public static AudioClip LoadWav(string filePath, out float[] samples)
    {
        samples = null;

        if (!File.Exists(filePath))
        {
            Debug.LogError("Wav file not found at: " + filePath);
            return null;
        }

        byte[] wavBytes = File.ReadAllBytes(filePath);

        // Read header fields
        ushort audioFormat = BitConverter.ToUInt16(wavBytes, 20); // 1 = PCM, 3 = IEEE float
        int channels = BitConverter.ToUInt16(wavBytes, 22);
        int sampleRate = BitConverter.ToInt32(wavBytes, 24);
        int byteRate = BitConverter.ToInt32(wavBytes, 28);
        ushort blockAlign = BitConverter.ToUInt16(wavBytes, 32);
        ushort bitsPerSample = BitConverter.ToUInt16(wavBytes, 34);

        // Find "data" chunk offset
        int pos = 12;
        while (!(wavBytes[pos] == 'd' && wavBytes[pos + 1] == 'a' && wavBytes[pos + 2] == 't' && wavBytes[pos + 3] == 'a'))
        {
            pos += 4;
            if (pos + 4 > wavBytes.Length)
            {
                Debug.LogError("Cannot find data chunk in WAV file.");
                return null;
            }
            int chunkSize = BitConverter.ToInt32(wavBytes, pos);
            pos += 4 + chunkSize;
            if (pos >= wavBytes.Length)
            {
                Debug.LogError("Cannot find data chunk in WAV file.");
                return null;
            }
        }

        pos += 4;
        if (pos + 4 > wavBytes.Length)
        {
            Debug.LogError("Invalid WAV file structure.");
            return null;
        }

        int dataSize = BitConverter.ToInt32(wavBytes, pos);
        pos += 4;

        int bytesPerSample = bitsPerSample / 8;
        int sampleCount = dataSize / bytesPerSample;

        samples = new float[sampleCount];

        try
        {
            if (audioFormat == 1) // PCM integer
            {
                if (bitsPerSample == 16)
                {
                    for (int i = 0; i < sampleCount; i++)
                    {
                        short sample = BitConverter.ToInt16(wavBytes, pos + i * 2);
                        samples[i] = sample / 32768f;
                    }
                }
                else if (bitsPerSample == 8)
                {
                    for (int i = 0; i < sampleCount; i++)
                    {
                        samples[i] = (wavBytes[pos + i] - 128) / 128f;
                    }
                }
                else
                {
                    Debug.LogError("PCM WAV bit depth not supported: " + bitsPerSample);
                    return null;
                }
            }
            else if (audioFormat == 3) // IEEE float
            {
                if (bitsPerSample == 32)
                {
                    for (int i = 0; i < sampleCount; i++)
                    {
                        samples[i] = BitConverter.ToSingle(wavBytes, pos + i * 4);
                    }
                }
                else
                {
                    Debug.LogError("Float WAV bit depth not supported: " + bitsPerSample);
                    return null;
                }
            }
            else
            {
                Debug.LogError("Unsupported WAV audio format: " + audioFormat);
                return null;
            }
        }
        catch (Exception e)
        {
            Debug.LogError("Exception reading WAV samples: " + e.Message);
            return null;
        }

        // Create AudioClip - mono by averaging channels if necessary
        int totalSamples = sampleCount / channels;
        AudioClip audioClip = AudioClip.Create(Path.GetFileNameWithoutExtension(filePath), totalSamples, 1, sampleRate, false);

        if (channels == 1)
        {
            audioClip.SetData(samples, 0);
        }
        else if (channels > 1)
        {
            float[] monoSamples = new float[totalSamples];
            for (int i = 0; i < totalSamples; i++)
            {
                float sum = 0f;
                for (int c = 0; c < channels; c++)
                {
                    sum += samples[i * channels + c];
                }
                monoSamples[i] = sum / channels;
            }
            audioClip.SetData(monoSamples, 0);
            samples = monoSamples; // Override samples as mono
        }
        else
        {
            Debug.LogError("Invalid number of channels: " + channels);
            return null;
        }

        return audioClip;
    }

    #endregion
}