PDA

View Full Version : سوال: پخش موزیک در سایت



saninnnnnnnn
شنبه 23 دی 1391, 11:23 صبح
سلام
من یک بار دیگر پرسیده بودم ولی کسی جواب نداد
چطوری م یتوانم یک موزیک در سایت بگذارم که پخش شود با سی شارپ

amir22448
شنبه 23 دی 1391, 12:47 عصر
سلام من سورس رو از آدرس زیر اوردم :
http://www.codeproject.com/Articles/4712/Playing-wav-files-using-C
البته این برای C# هست

Function های پخش موزیک:
bool PlaySound(
LPCSTR pszSound, // filename
HMODULE hmod, // handle to resource file
DWORD fdwSound) // sound flags



کد اصلی:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices; // for PInvoke
using Microsoft.Win32; // RegistryKey

namespace PlaySound
{
public class Form1 : System.Windows.Forms.Form
{
...
private RegistryKey key1;
private RegistryKey key2;




// collection of user-defined sound events
private PropertyCollection events;

// PlaySound()
[DllImport("winmm.dll", SetLastError=true,
CallingConvention=CallingConvention.Winapi)]
static extern bool PlaySound(
string pszSound,
IntPtr hMod,
SoundFlags sf );

// Flags for playing sounds. For this example, we are reading
// the sound from a filename, so we need only specify
// SND_FILENAME | SND_ASYNC
[Flags]
public enum SoundFlags : int
{
SND_SYNC = 0x0000, // play synchronously (default)
SND_ASYNC = 0x0001, // play asynchronously
SND_NODEFAULT = 0x0002, // silence (!default) if sound not found
SND_MEMORY = 0x0004, // pszSound points to a memory file
SND_LOOP = 0x0008, // loop the sound until next sndPlaySound
SND_NOSTOP = 0x0010, // don't stop any currently playing sound
SND_NOWAIT = 0x00002000, // don't wait if the driver is busy
SND_ALIAS = 0x00010000, // name is a registry alias
SND_ALIAS_ID = 0x00110000, // alias is a predefined ID
SND_FILENAME = 0x00020000, // name is file name
SND_RESOURCE = 0x00040004 // name is resource name or atom
}

...

private void buttonPlay_Click(object sender, System.EventArgs e)
{
int err = 0; // last error

try
{
// play the sound from the selected filename
if (!PlaySound( tbFileName.Text, IntPtr.Zero,
SoundFlags.SND_FILENAME | SoundFlags.SND_ASYNC ))
MessageBox.Show(this,
"Unable to find specified sound file or " +
"default Windows sound");
}
catch
{
// grab the underlying Win32 error code
err = Marshal.GetLastWin32Error();
if (err != 0)
MessageBox.Show( this,
"Error " + err.ToString(),
"PlaySound() failed",
MessageBoxButtons.OK,
MessageBoxIcon.Error );
}
}

// browse button handler
private void buttonBrowse_Click(object sender, System.EventArgs e)
{
string sysRoot = System.Environment.SystemDirectory;
OpenFileDialog dlg = new OpenFileDialog();
dlg.AddExtension = true;
dlg.Filter = "Wave files (*.wav)|*.wav|All files (*.*)|*.*" ;
// start in media folder
dlg.InitialDirectory = sysRoot + @"\..\Media";
// open dialog
if(dlg.ShowDialog(this) == DialogResult.OK)
{
tbFileName.Text = dlg.FileName;
}
}

...

// fill combobox with user-defined sounds
private void PopulateDropDown()
{
// fill our PropertyCollection object
events = GetUserDefinedSounds();

// disable if no sound events
if (events.Keys.Count == 0)
cbUserSound.Enabled = false;
else
{
foreach (string key in events.Keys)
{
cbUserSound.Items.Add(key);
}
}
}

// Retrieves the user-defined sounds from the registry
private PropertyCollection GetUserDefinedSounds()
{
string rootKey = "AppEvents\\Schemes\\Apps\\.Default";
PropertyCollection coll = new PropertyCollection();

try
{
// open root key
key1 = Registry.CurrentUser.OpenSubKey(rootKey, false);

// go through each subkey
foreach (string subKey in key1.GetSubKeyNames())
{
// open subkey
key2 = key1.OpenSubKey(subKey + "\\.Current", false);

// get filename, if any
if (key2 != null)
if (key2.GetValue(null).ToString().Length > 0)
coll.Add(subKey, key2.GetValue(null).ToString());
}
}
catch (Exception ex)
{
MessageBox.Show(this, ex.Message, "Yikes!",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
// close keys
key1.Close();
key2.Close();
}

return coll;
}

...
}
}

sasanrstm
شنبه 23 دی 1391, 15:27 عصر
سلام
من یک بار دیگر پرسیده بودم ولی کسی جواب نداد
چطوری م یتوانم یک موزیک در سایت بگذارم که پخش شود با سی شارپ
اینم کد پخش آهنگ که پلیر هم داره فقط کافی آدرس مکانی که آهنگت آپلود شده رو قرار بدی تو قسمت html کدو بزار


<embed type="application/x-shockwave-flash" flashvars="audioUrl=ADRESSE AHANG???" src="http://www.google.com/reader/ui/3523697345-audio-player.swf" width="300" height="40" quality="best"></embed>
تو سایت خودم گذاشتم اما فیلتر شده اگه با فیلتر شکن بری آهنگهام پخش میشن مشگل از کد نیست آ مخابرات فیلتر کرده