PDA

View Full Version : سوال: embed کردن فایل



alirzn
شنبه 04 خرداد 1387, 18:01 عصر
من می خوام فایل فیلمی رو embed کنم. یعنی فایل رو تو دل برنامه ببرم که کسی نتونه اونو بدون برنامه باز کنه. چطور میتونم این کارو کنم؟

علیرضا مداح
شنبه 04 خرداد 1387, 21:15 عصر
سلام دوست عزیز
باید فایل مورد نظر را به عنوان Resource به پروژه اضافه کنید ،
به عنوان یک مثال بسیار ساده یک پروژه جدید ایجاد کنید ،
در سولوشن اکسپلورر Properties را باز کنید و سپس بر روی Resources.resx دابل کلیک کنید ،
هم اکنون Add Resource و سپس Add Existing File را انتخاب کرده و یک فایل به Resource اضافه نمایید ،
حال میتوانید توسط کد زیر به آن دسترسی پیدا نمایید :


WindowsApplication11.Properties.Resources.Resource Name

alirzn
یک شنبه 05 خرداد 1387, 07:45 صبح
این کارو انجام دادم . اما این کار byte بر میگردونه و player من که flv player هست فقط path فایل رو میگیره و باز میکنه.


سلام دوست عزیز
باید فایل مورد نظر را به عنوان Resource به پروژه اضافه کنید ،
به عنوان یک مثال بسیار ساده یک پروژه جدید ایجاد کنید ،
در سولوشن اکسپلورر Properties را باز کنید و سپس بر روی Resources.resx دابل کلیک کنید ،
هم اکنون Add Resource و سپس Add Existing File را انتخاب کرده و یک فایل به Resource اضافه نمایید ،
حال میتوانید توسط کد زیر به آن دسترسی پیدا نمایید :


WindowsApplication11.Properties.Resources.Resource Name

hassan razavi
یک شنبه 05 خرداد 1387, 08:00 صبح
byte ها رو توسط Stream به فایل تبدیل کنید یا مستقیما از Stream پخش کنید

gdevnb
دوشنبه 06 خرداد 1387, 18:16 عصر
این کار رو از طریق F-in-box هم میتونید انجام بدین.

alirzn
دوشنبه 06 خرداد 1387, 19:50 عصر
من همین کارو چطور میتونم انجام بدم؟ flash player من فقط url میگیره نه byte. من source رو گذاشتم. ممنون میشم راهنمایی کنید


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Xml;
using AxShockwaveFlashObjects;

namespace Vml.FLVPlayer
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class FLVPlayer : System.Windows.Forms.Form
{
private StatusBar statusbar;
private StatusBarPanel fileNameStatusBarPanel;
private System.Windows.Forms.Panel videoPlaceholder;
private System.Windows.Forms.Button openVideo;
private System.Windows.Forms.OpenFileDialog openVideoDialog;
private AxShockwaveFlashObjects.AxShockwaveFlash flashPlayer;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public FLVPlayer()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
try
{
flashPlayer.LoadMovie(0, Application.StartupPath + "\\player.swf");
flashPlayer.FlashCall += new _IShockwaveFlashEvents_FlashCallEventHandler(flash Player_FlashCall);
}
catch(Exception ex)
{
ExceptionUtilities.DisplayException("Unable to load SWF video player, please verify you have Flash Player 8 installed and try again.");
this.Dispose();
}
}
public FLVPlayer(string moviePath):this()
{
this.LoadVideo(moviePath);
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typ eof(FLVPlayer));
this.openVideo = new System.Windows.Forms.Button();
this.openVideoDialog = new System.Windows.Forms.OpenFileDialog();
this.statusbar = new System.Windows.Forms.StatusBar();
this.fileNameStatusBarPanel = new System.Windows.Forms.StatusBarPanel();
this.videoPlaceholder = new System.Windows.Forms.Panel();
this.flashPlayer = new AxShockwaveFlashObjects.AxShockwaveFlash();
((System.ComponentModel.ISupportInitialize)(this.f ileNameStatusBarPanel)).BeginInit();
this.videoPlaceholder.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.f lashPlayer)).BeginInit();
this.SuspendLayout();
//
// openVideo
//
this.openVideo.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.openVideo.Location = new System.Drawing.Point(12, 302);
this.openVideo.Name = "openVideo";
this.openVideo.Size = new System.Drawing.Size(88, 23);
this.openVideo.TabIndex = 1;
this.openVideo.Text = "Open...";
this.openVideo.Click += new System.EventHandler(this.openVideo_Click);
//
// statusbar
//
this.statusbar.Location = new System.Drawing.Point(0, 401);
this.statusbar.Name = "statusbar";
this.statusbar.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
this.fileNameStatusBarPanel});
this.statusbar.ShowPanels = true;
this.statusbar.Size = new System.Drawing.Size(875, 22);
this.statusbar.SizingGrip = false;
this.statusbar.TabIndex = 4;
//
// fileNameStatusBarPanel
//
this.fileNameStatusBarPanel.Name = "fileNameStatusBarPanel";
this.fileNameStatusBarPanel.Text = "File not loaded";
this.fileNameStatusBarPanel.ToolTipText = "The file currently loaded";
this.fileNameStatusBarPanel.Width = 810;
//
// videoPlaceholder
//
this.videoPlaceholder.BackColor = System.Drawing.Color.Black;
this.videoPlaceholder.Controls.Add(this.flashPlaye r);
this.videoPlaceholder.Location = new System.Drawing.Point(8, 8);
this.videoPlaceholder.Name = "videoPlaceholder";
this.videoPlaceholder.Size = new System.Drawing.Size(487, 266);
this.videoPlaceholder.TabIndex = 6;
//
// flashPlayer
//
this.flashPlayer.Enabled = true;
this.flashPlayer.Location = new System.Drawing.Point(0, 0);
this.flashPlayer.Name = "flashPlayer";
this.flashPlayer.OcxState = ((System.Windows.Forms.AxHost.State)(resources.Get Object("flashPlayer.OcxState")));
this.flashPlayer.Size = new System.Drawing.Size(484, 263);
this.flashPlayer.TabIndex = 0;
//
// FLVPlayer
//
this.AccessibleName = "FLVPlayer";
this.AllowDrop = true;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(875, 423);
this.Controls.Add(this.statusbar);
this.Controls.Add(this.openVideo);
this.Controls.Add(this.videoPlaceholder);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.Name = "FLVPlayer";
this.Text = "FLVPlayer";
this.DragDrop += new System.Windows.Forms.DragEventHandler(this.FLVPlay er_DragDrop);
this.DragEnter += new System.Windows.Forms.DragEventHandler(this.FLVPlay er_DragEnter);
((System.ComponentModel.ISupportInitialize)(this.f ileNameStatusBarPanel)).EndInit();
this.videoPlaceholder.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.f lashPlayer)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void openVideo_Click(object sender, System.EventArgs e)
{
openVideoDialog = new OpenFileDialog();
openVideoDialog.Filter = "*.flv|*.flv";
openVideoDialog.Title = "Select a Flash Video file...";
openVideoDialog.Multiselect = false;
openVideoDialog.RestoreDirectory = true;
if(openVideoDialog.ShowDialog() == DialogResult.OK)
{
LoadVideo(openVideoDialog.FileName);
}
}
private void LoadVideo(string videoPath)
{
fileNameStatusBarPanel.Text = videoPath;

flashPlayer.CallFunction("<invoke name=\"loadAndPlayVideo\" returntype=\"xml\"><arguments><string>" + videoPath + "</string></arguments></invoke>");
}
private void FLVPlayer_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
if(fileNameStatusBarPanel.Text != files[0])
{
LoadVideo(files[0]);
}
}
private void FLVPlayer_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
if(e.Data.GetDataPresent(DataFormats.FileDrop, false))
{
e.Effect = DragDropEffects.All;
}
}
// private void btnUrl_Click(object sender, System.EventArgs e)
// {
// UrlDialog urlForm = new UrlDialog();
//
// if(urlForm.ShowDialog(this) == DialogResult.OK)
// {
// if(urlForm.Url != null && urlForm.Url.Length > 0)
// {
// LoadVideo(urlForm.Url);
// }
// }
// }
public void ResizePlayer(int width, int height)
{
width = 320;
height = 240;
flashPlayer.Width = width;
flashPlayer.Height = height;
videoPlaceholder.Width = width;
videoPlaceholder.Height = height;

}
private void flashPlayer_FlashCall(object sender, _IShockwaveFlashEvents_FlashCallEvent e)
{
XmlDocument document = new XmlDocument();
document.LoadXml(e.request);

// Since I have only one call back I just grab the arguments and call
// the function. This needs to be made much more flexible when there are
// multiple call backs going back and forth
XmlNodeList list = document.GetElementsByTagName("arguments");
ResizePlayer(Convert.ToInt32(list[0].FirstChild.InnerText), Convert.ToInt32(list[0].ChildNodes[1].InnerText));
}
}
}


byte ها رو توسط Stream به فایل تبدیل کنید یا مستقیما از Stream پخش کنید

Chabok
سه شنبه 07 خرداد 1387, 12:15 عصر
سلام

flash player من فقط url میگیره نه byte
پس ناچار به ذخیره فایل روی هارد هستید و سپس دادن مسیر به فلش پلیر
میتونید هنگام شروع فایل رو با پسوندی ناشناس و نامی گمراه کننده در مسیری پنهان :لبخند: ذخیره کنید و پس از اتمام کار آن را پاک کنید .
موفق باشید . خدانگهدار

gdevnb
سه شنبه 07 خرداد 1387, 17:45 عصر
http://barnamenevis.org/forum/showpost.php?p=510242&postcount=33