![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/soundstudiopro.com/private_html/utils/ |
<?php
session_start();
// Check if user is logged in
if (!isset($_SESSION['user_id'])) {
header('Location: /auth/login.php');
exit;
}
require_once 'config/database.php';
$pdo = getDBConnection();
// Get user name from database
$stmt = $pdo->prepare("SELECT name, credits FROM users WHERE id = ?");
$stmt->execute([$_SESSION['user_id']]);
$user = $stmt->fetch();
$user_name = $user['name'] ?? 'User';
$credits = $user['credits'] ?? 0;
// Update session credits
$_SESSION['credits'] = $credits;
// Set page variables for header
$page_title = 'Create Music - SoundStudioPro';
$page_description = 'Create professional AI-generated music with custom prompts and advanced settings.';
// Include header
include 'includes/header.php';
?>
<style>
/* Main Content */
.main-content {
margin-top: 10rem;
padding: 4rem 0;
min-height: calc(100vh - 10rem);
}
/* Hero Section */
.hero {
padding: 8rem 0 6rem;
text-align: center;
color: white;
background: linear-gradient(135deg, #0a0a0a 0%, #1a1a1a 50%, #0a0a0a 100%);
position: relative;
overflow: hidden;
margin-bottom: 4rem;
}
.hero::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grid" width="10" height="10" patternUnits="userSpaceOnUse"><path d="M 10 0 L 0 0 0 10" fill="none" stroke="rgba(102,126,234,0.1)" stroke-width="0.5"/></pattern></defs><rect width="100" height="100" fill="url(%23grid)"/></svg>');
opacity: 0.3;
}
.hero-content {
max-width: 90rem;
margin: 0 auto;
position: relative;
z-index: 2;
}
.hero-badge {
display: inline-block;
background: linear-gradient(135deg, rgba(102, 126, 234, 0.2), rgba(118, 75, 162, 0.2));
color: #667eea;
padding: 1.2rem 2.4rem;
border-radius: 50px;
font-size: 1.4rem;
font-weight: 600;
margin-bottom: 3rem;
backdrop-filter: blur(10px);
border: 1px solid rgba(102, 126, 234, 0.3);
}
.hero-title {
font-size: 5.6rem;
font-weight: 900;
line-height: 1.1;
margin-bottom: 2.4rem;
background: linear-gradient(135deg, #ffffff, #667eea, #764ba2);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.hero-subtitle {
font-size: 2rem;
font-weight: 400;
margin-bottom: 4rem;
opacity: 0.9;
max-width: 70rem;
margin-left: auto;
margin-right: auto;
color: #a0aec0;
}
/* Create Content */
.create-content {
background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
padding: 6rem 0;
border-radius: 40px 40px 0 0;
margin-top: -2rem;
position: relative;
z-index: 10;
}
.create-container {
max-width: 80rem;
margin: 0 auto;
}
/* Credits Info */
.credits-info {
background: rgba(102, 126, 234, 0.1);
border: 1px solid rgba(102, 126, 234, 0.3);
border-radius: 16px;
padding: 3rem;
margin-bottom: 4rem;
text-align: center;
backdrop-filter: blur(20px);
}
.credits-number {
font-size: 3.6rem;
font-weight: 900;
color: #667eea;
margin-bottom: 1rem;
}
.credits-label {
font-size: 1.6rem;
color: #a0aec0;
font-weight: 500;
}
/* Create Form */
.create-form {
background: rgba(255, 255, 255, 0.05);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 24px;
padding: 4rem;
backdrop-filter: blur(20px);
}
.form-group {
margin-bottom: 3rem;
}
.form-label {
display: block;
font-size: 1.6rem;
font-weight: 600;
margin-bottom: 1rem;
color: white;
}
.form-input,
.form-textarea,
.form-select {
width: 100%;
padding: 1.5rem 2rem;
border: 2px solid rgba(255, 255, 255, 0.1);
border-radius: 12px;
background: rgba(255, 255, 255, 0.05);
color: white;
font-size: 1.6rem;
transition: all 0.3s ease;
}
.form-input:focus,
.form-textarea:focus,
.form-select:focus {
outline: none;
border-color: #667eea;
background: rgba(255, 255, 255, 0.1);
}
.form-textarea {
min-height: 15rem;
resize: vertical;
}
.form-input::placeholder {
color: rgba(255, 255, 255, 0.6);
}
.form-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 2rem;
}
.submit-btn {
background: linear-gradient(135deg, #667eea, #764ba2);
color: white;
border: none;
padding: 2rem 3rem;
border-radius: 16px;
font-size: 1.8rem;
font-weight: 700;
cursor: pointer;
width: 100%;
transition: all 0.3s ease;
display: flex;
align-items: center;
justify-content: center;
gap: 1rem;
}
.submit-btn:hover:not(:disabled) {
transform: translateY(-3px);
box-shadow: 0 15px 40px rgba(102, 126, 234, 0.4);
}
.submit-btn:disabled {
opacity: 0.6;
cursor: not-allowed;
transform: none;
}
/* Results Section */
.results-section {
margin-top: 4rem;
display: none;
}
.results-header {
text-align: center;
margin-bottom: 3rem;
}
.results-title {
font-size: 3.2rem;
font-weight: 700;
color: white;
margin-bottom: 1rem;
}
.audio-player {
background: rgba(255, 255, 255, 0.05);
padding: 3rem;
border-radius: 20px;
margin-bottom: 2rem;
border: 1px solid rgba(255, 255, 255, 0.1);
}
.audio-player audio {
width: 100%;
border-radius: 12px;
}
.download-btn {
display: inline-flex;
align-items: center;
gap: 1rem;
padding: 1.5rem 3rem;
background: linear-gradient(135deg, #48bb78, #38a169);
color: white;
text-decoration: none;
border-radius: 12px;
font-weight: 600;
transition: all 0.3s ease;
}
.download-btn:hover {
transform: translateY(-2px);
box-shadow: 0 10px 30px rgba(72, 187, 120, 0.3);
}
/* Responsive */
@media (max-width: 768px) {
.hero-title {
font-size: 4rem;
}
.form-row {
grid-template-columns: 1fr;
}
.create-form {
padding: 2rem;
}
}
</style>
<!-- Hero Section -->
<section class="hero">
<div class="container">
<div class="hero-content">
<div class="hero-badge">🎵 Create Music</div>
<h1 class="hero-title">Create Professional AI Music</h1>
<p class="hero-subtitle">Generate studio-quality music with custom prompts. Choose from multiple AI models and create tracks that match your creative vision.</p>
</div>
</div>
</section>
<!-- Create Content -->
<section class="create-content">
<div class="container">
<div class="create-container">
<!-- Credits Info -->
<div class="credits-info">
<div class="credits-number"><?= $credits ?></div>
<div class="credits-label">Credits Available</div>
</div>
<!-- Create Form -->
<div class="create-form">
<form id="musicForm">
<div class="form-group">
<label class="form-label">Music Type</label>
<select class="form-select" id="musicType" required>
<option value="">Select music type</option>
<option value="music">AI Music Generation</option>
<option value="lyrics">Lyrics Generation</option>
<option value="wav">WAV Conversion</option>
<option value="vocal-removal">Vocal Removal</option>
<option value="music-video">Music Video Generation</option>
<option value="extend">Track Extension</option>
</select>
</div>
<div class="form-group">
<label class="form-label">Prompt / Description</label>
<textarea class="form-textarea" id="prompt" placeholder="Describe the music you want to create. Be specific about genre, mood, instruments, tempo, etc. Example: 'An upbeat electronic dance track with heavy bass, synthesizers, and a driving beat. Should be energetic and perfect for a workout playlist.'" required></textarea>
</div>
<div class="form-row">
<div class="form-group">
<label class="form-label">Model Version</label>
<select class="form-select" id="modelVersion">
<option value="v3">v3 (Latest)</option>
<option value="v2">v2 (Stable)</option>
<option value="v1">v1 (Classic)</option>
</select>
</div>
<div class="form-group">
<label class="form-label">Duration (seconds)</label>
<input type="number" class="form-input" id="duration" value="30" min="10" max="300" required>
</div>
</div>
<button type="submit" class="submit-btn" id="createBtn">
<span id="loading" style="display: none;">
<i class="fas fa-spinner fa-spin"></i> Creating Music...
</span>
<span id="createText">
<i class="fas fa-magic"></i> Create Music
</span>
</button>
</form>
<!-- Results Section -->
<div id="results" class="results-section">
<div class="results-header">
<h3 class="results-title">Your Music is Ready!</h3>
</div>
<div id="audioPlayer" class="audio-player">
<audio id="audioElement" controls>
Your browser does not support the audio element.
</audio>
</div>
<a id="downloadBtn" href="#" class="download-btn">
<i class="fas fa-download"></i> Download MP3
</a>
</div>
</div>
</div>
</div>
</section>
<script>
// Secure API Configuration
const API_ENDPOINT = window.location.protocol + '//' + window.location.host + '/api.php';
// DOM Elements
const musicForm = document.getElementById('musicForm');
const createBtn = document.getElementById('createBtn');
const loading = document.getElementById('loading');
const results = document.getElementById('results');
const audioElement = document.getElementById('audioElement');
const downloadBtn = document.getElementById('downloadBtn');
// Form submission handler
musicForm.addEventListener('submit', async (e) => {
e.preventDefault();
const musicType = document.getElementById('musicType').value;
const prompt = document.getElementById('prompt').value;
const modelVersion = document.getElementById('modelVersion').value;
const duration = document.getElementById('duration').value;
// Show loading
createBtn.disabled = true;
loading.style.display = 'block';
results.style.display = 'none';
try {
// Prepare request data
const requestData = {
type: musicType,
prompt: prompt,
model_version: modelVersion,
duration: parseInt(duration)
};
console.log('Sending request:', requestData);
// Make API request
const response = await fetch(API_ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(requestData)
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const responseText = await response.text();
console.log('Raw response:', responseText);
let result;
try {
result = JSON.parse(responseText);
} catch (parseError) {
console.error('JSON parse error:', parseError);
console.error('Response text:', responseText);
throw new Error('Invalid JSON response from server: ' + responseText.substring(0, 100));
}
if (!result.success) {
throw new Error(result.error || 'Unknown error occurred');
}
// Check if this is a processing response (callback-based)
if (result.data && result.data.status === 'processing' && result.data.taskId) {
// Start polling for results
pollForResults(result.data.taskId);
} else {
// Direct result (for non-callback operations)
displayResults(result.data);
}
} catch (fetchError) {
if (fetchError.name === 'AbortError') {
throw new Error('Request timed out. Music generation takes 2-3 minutes. Please try again.');
}
throw fetchError;
}
} catch (error) {
console.error('Error creating music:', error);
console.error('Error details:', error);
// More detailed error handling
let errorMessage = 'Error creating music: ';
if (error.message) {
errorMessage += error.message;
} else if (error.toString) {
errorMessage += error.toString();
} else {
errorMessage += 'Unknown error occurred';
}
alert(errorMessage);
} finally {
// Hide loading
createBtn.disabled = false;
loading.style.display = 'none';
}
});
// Poll for task results
async function pollForResults(taskId) {
const maxAttempts = 60; // 5 minutes with 5-second intervals
let attempts = 0;
const pollInterval = setInterval(async () => {
attempts++;
try {
const response = await fetch(`/get_result.php?taskId=${taskId}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const result = await response.json();
if (result.success && result.status === 'complete') {
clearInterval(pollInterval);
displayResults(result.data);
createBtn.disabled = false;
loading.style.display = 'none';
} else if (result.success && result.status === 'processing') {
// Update loading message
const loadingText = document.querySelector('#loading p');
if (loadingText) {
loadingText.textContent = `Creating your music... This may take 2-3 minutes. (Attempt ${attempts}/${maxAttempts})`;
}
// Check if we've exceeded max attempts
if (attempts >= maxAttempts) {
clearInterval(pollInterval);
throw new Error('Music generation timed out. Please try again.');
}
} else {
throw new Error(result.error || 'Unknown error occurred');
}
} catch (error) {
clearInterval(pollInterval);
console.error('Polling error:', error);
alert('Error checking music status: ' + error.message);
createBtn.disabled = false;
loading.style.display = 'none';
}
}, 5000); // Poll every 5 seconds
}
// Display results
function displayResults(data) {
results.style.display = 'block';
console.log('Displaying results:', data);
// Handle api.box callback data format
if (data && data.audio_url) {
audioElement.src = data.audio_url;
downloadBtn.href = data.audio_url;
downloadBtn.download = 'soundstudiopro-creation.mp3';
} else if (data && data.data && data.data.audio_url) {
// Nested data format from callback
audioElement.src = data.data.audio_url;
downloadBtn.href = data.data.audio_url;
downloadBtn.download = 'soundstudiopro-creation.mp3';
} else if (data && data.lyrics) {
// For lyrics, display text instead of audio
const audioPlayer = document.getElementById('audioPlayer');
audioPlayer.innerHTML = `
<div style="color: white; text-align: center; padding: 2rem;">
<h4 style="margin-bottom: 1rem;">Generated Lyrics:</h4>
<p style="white-space: pre-wrap; line-height: 1.6;">${data.lyrics}</p>
</div>
`;
} else if (data && data.video_url) {
// For music videos
const audioPlayer = document.getElementById('audioPlayer');
audioPlayer.innerHTML = `
<div style="color: white; text-align: center; padding: 2rem;">
<h4 style="margin-bottom: 1rem;">Generated Music Video:</h4>
<video controls style="width: 100%; max-width: 500px; border-radius: 12px;">
<source src="${data.video_url}" type="video/mp4">
Your browser does not support the video tag.
</video>
<div style="margin-top: 2rem;">
<a href="${data.video_url}" class="download-btn" download="musicstudio-video.mp4">
<i class="fas fa-download"></i> Download Video
</a>
</div>
</div>
`;
} else {
// Fallback for other types
const audioPlayer = document.getElementById('audioPlayer');
audioPlayer.innerHTML = `
<div style="color: white; text-align: center; padding: 2rem;">
<h4 style="margin-bottom: 1rem;">Processing Complete!</h4>
<p>Your ${document.getElementById('musicType').value} has been generated successfully.</p>
<p style="font-size: 1.4rem; color: #a0aec0; margin-top: 1rem;">Check the console for detailed response data.</p>
</div>
`;
console.log('API Response:', data);
}
}
</script>
<!-- Winamp-style Player -->
<div class="winamp-container" id="player" style="display: none;">
<div class="player-main">
<div class="player-controls">
<button class="control-btn" onclick="previousTrack()">
<i class="fas fa-step-backward"></i>
</button>
<button class="control-btn play-btn" id="playPauseBtn" onclick="togglePlay()">
<i class="fas fa-play" id="playIcon"></i>
</button>
<button class="control-btn" onclick="nextTrack()">
<i class="fas fa-step-forward"></i>
</button>
</div>
<div class="track-info">
<div class="track-title" id="currentTrackTitle">No track selected</div>
<div class="track-artist" id="currentTrackArtist">SoundStudioPro</div>
</div>
<div class="progress-container">
<div class="progress-bar" onclick="seek(event)">
<div class="progress-fill" id="progressFill"></div>
</div>
<div class="time-display">
<span id="currentTime">0:00</span> / <span id="totalTime">0:00</span>
</div>
</div>
<div class="volume-control">
<i class="fas fa-volume-up"></i>
<div class="volume-slider" onclick="setVolume(event)">
<div style="width: 70%; height: 100%; background: #3498db;"></div>
</div>
</div>
</div>
</div>
<style>
/* Winamp-style Player */
.winamp-container {
position: fixed;
bottom: 0;
left: 0;
right: 0;
z-index: 1000;
background: linear-gradient(90deg, #2c3e50, #34495e);
border-top: 2px solid #3498db;
box-shadow: 0 -5px 20px rgba(0,0,0,0.3);
}
.player-main {
display: flex;
align-items: center;
padding: 10px 20px;
height: 80px;
}
.player-controls {
display: flex;
align-items: center;
gap: 15px;
flex: 1;
}
.control-btn {
background: #3498db;
border: none;
color: white;
padding: 8px 12px;
border-radius: 5px;
cursor: pointer;
transition: all 0.3s;
}
.control-btn:hover {
background: #2980b9;
transform: scale(1.05);
}
.play-btn {
background: #27ae60;
padding: 12px 16px;
border-radius: 50%;
}
.play-btn:hover {
background: #229954;
}
.track-info {
flex: 1;
margin: 0 20px;
}
.track-title {
font-weight: bold;
font-size: 14px;
margin-bottom: 5px;
}
.track-artist {
font-size: 12px;
opacity: 0.8;
}
.progress-container {
flex: 1;
margin: 0 20px;
}
.progress-bar {
width: 100%;
height: 6px;
background: #34495e;
border-radius: 3px;
overflow: hidden;
cursor: pointer;
}
.progress-fill {
height: 100%;
background: linear-gradient(90deg, #3498db, #27ae60);
width: 0%;
transition: width 0.1s;
}
.time-display {
font-size: 12px;
margin-top: 5px;
text-align: center;
}
.volume-control {
display: flex;
align-items: center;
gap: 10px;
margin-left: 20px;
}
.volume-slider {
width: 80px;
height: 4px;
background: #34495e;
border-radius: 2px;
cursor: pointer;
}
</style>
<script>
let currentAudio = null;
let currentTrackIndex = 0;
let playlist = [];
let isPlaying = false;
// Play track
function playTrack(audioUrl, title, artist) {
if (currentAudio) {
currentAudio.pause();
currentAudio = null;
}
currentAudio = new Audio(audioUrl);
currentAudio.addEventListener('loadedmetadata', () => {
document.getElementById('totalTime').textContent = formatTime(currentAudio.duration);
});
currentAudio.addEventListener('timeupdate', () => {
const progress = (currentAudio.currentTime / currentAudio.duration) * 100;
document.getElementById('progressFill').style.width = progress + '%';
document.getElementById('currentTime').textContent = formatTime(currentAudio.currentTime);
});
currentAudio.addEventListener('ended', () => {
nextTrack();
});
// Auto-play disabled - user must click play button
// currentAudio.play();
// isPlaying = true;
document.getElementById('currentTrackTitle').textContent = title;
document.getElementById('currentTrackArtist').textContent = artist;
document.getElementById('playIcon').className = 'fas fa-play'; // Show play button since auto-play is disabled
// Show player
document.getElementById('player').style.display = 'block';
// Update current track index
currentTrackIndex = playlist.findIndex(track => track.audioUrl === audioUrl);
}
// Toggle play/pause
function togglePlay() {
if (!currentAudio) return;
if (isPlaying) {
currentAudio.pause();
document.getElementById('playIcon').className = 'fas fa-play';
} else {
currentAudio.play();
document.getElementById('playIcon').className = 'fas fa-pause';
}
isPlaying = !isPlaying;
}
// Next track
function nextTrack() {
if (playlist.length === 0) return;
currentTrackIndex = (currentTrackIndex + 1) % playlist.length;
const track = playlist[currentTrackIndex];
playTrack(track.audioUrl, track.title, track.artist);
}
// Previous track
function previousTrack() {
if (playlist.length === 0) return;
currentTrackIndex = currentTrackIndex === 0 ? playlist.length - 1 : currentTrackIndex - 1;
const track = playlist[currentTrackIndex];
playTrack(track.audioUrl, track.title, track.artist);
}
// Seek in track
function seek(event) {
if (!currentAudio) return;
const rect = event.target.getBoundingClientRect();
const clickX = event.clientX - rect.left;
const width = rect.width;
const seekTime = (clickX / width) * currentAudio.duration;
currentAudio.currentTime = seekTime;
}
// Set volume
function setVolume(event) {
if (!currentAudio) return;
const rect = event.target.getBoundingClientRect();
const clickX = event.clientX - rect.left;
const width = rect.width;
const volume = clickX / width;
currentAudio.volume = volume;
}
// Format time
function formatTime(seconds) {
const mins = Math.floor(seconds / 60);
const secs = Math.floor(seconds % 60);
return `${mins}:${secs.toString().padStart(2, '0')}`;
}
</script>
<?php include 'includes/footer.php'; ?>