Форум Flasher.ru

Форум Flasher.ru (http://www.flasher.ru/forum/index.php)
-   ActionScript 1.0/2.0 (http://www.flasher.ru/forum/forumdisplay.php?f=93)
-   -   AutoPlay в видео плеере (http://www.flasher.ru/forum/showthread.php?t=149480)

ilikali 26.01.2011 01:37

AutoPlay в видео плеере
 
Есть видео плеер (работает со списком плей листов). Написан очень клево во многом сам разобрался (учитывая что на флеше не аля улю). Код не помещается поэтому напишу продолжение в коменте
Код AS1/AS2:

//
// INITITAL SETTINGS
//
// Set document stage and width here
stageW = 660;
stageH = 400;
// Set default volume here (percentage)
defaultVolume = 100;
// Set default buffer time here (seconds)
defaultBuffer = 3;
// Set default gallery here (0 = first gallery)
galleryID = 0;
//
// ORIGINAL VALUES (FOR FULLSCREEN/NORMAL MODE)
//
// Control clips
controls_mc.originX = controls_mc._x;
controls_mc.originY = controls_mc._y;
controls_mc.bg_mc.originWidth = controls_mc.bg_mc._width;
controls_mc.sound_time_mc.originX = controls_mc.sound_time_mc._x;
// Video holder
video_holder.originX = video_holder._x;
video_holder.originY = video_holder._y;
video_holder.originWidth = video_holder._width;
video_holder.originHeight = video_holder._height;
// Progress bar
controls_mc.progress_mc.originX = controls_mc.progress_mc._x;
controls_mc.progress_mc.originWidth = controls_mc.progress_mc._width;
//
// STAGE RESIZE (FOR FULLSCREEN/NORMAL MODE)
//
// Normal mode
objectsNormal = function () {
        // Control clips
        controls_mc._x = controls_mc.originX;
        controls_mc._y = controls_mc.originY;
        controls_mc.bg_mc._width = controls_mc.bg_mc.originWidth;
        controls_mc.sound_time_mc._x = controls_mc.sound_time_mc.originX;
        // Progress bar
        controls_mc.progress_mc._width = progress_mc.originWidth;
        // Video holder
        video_holder._x = video_holder.originX;
        video_holder._y = video_holder.originY;
        video_holder._width = video_holder.originWidth;
        video_holder._height = video_holder.originHeight;
        // Progress bar
        controls_mc.progress_mc._width = controls_mc.progress_mc.originWidth;
};
// Fullscreen mode
objectsFullscreen = function () {
        // Control clips
        controls_mc._x = Math.round(-(Stage.width-stageW)/2-40);
        controls_mc._y = Math.round(-(Stage.height-stageH)/2+Stage.height-25);
        controls_mc.bg_mc._width = Stage.width;
        controls_mc.sound_time_mc._x = controls_mc.bg_mc._width-controls_mc.sound_time_mc._width;
        // Video holder
        video_holder._x = Math.round(-(Stage.width-stageW)/2);
        video_holder._y = Math.round(-(Stage.height-stageH)/2);
        video_holder._width = Stage.width;
        video_holder._height = Stage.height-25;
        // Progress bar
        controls_mc.progress_mc._width = controls_mc.bg_mc._width-10-controls_mc.sound_time_mc._width-controls_mc.progress_mc.originX;
};
// Stage resize listener
Stage.scaleMode = "noScale";
stageListener = new Object(this);
Stage.addListener(stageListener);
alignObjects = function () {
        // Align background
        _parent.bg._width = Stage.width;
        _parent.bg._height = Stage.height;
        _parent.bg._x = -(Stage.width-stageW)/2;
        _parent.bg._y = -(Stage.height-stageH)/2;
        if (fullscreenMode) {
                objectsFullscreen();
        }
};
stageListener.onResize = function() {
        alignObjects();
};
alignObjects();
//
// FULLSCREEN MODE BUTTON
//
controls_mc.sound_time_mc.bttnFullscreen.bttn.onPress = function() {
        if (this._parent.icon_mc._currentframe == 1) {
                // Go fullscreen
                fullscreenMode = true;
                Stage["displayState"] = "fullScreen";
                this._parent.icon_mc.gotoAndStop(2);
                objectsFullscreen();
                this._parent.onEnterFrame = function() {
                        if (Stage["displayState"] == "normal" && fullscreenMode) {
                                fullscreenMode = false;
                                this.icon_mc.gotoAndStop(1);
                                objectsNormal();
                                delete this._parent.onEnterFrame;
                        }
                };
        } else {
                // Go normal
                delete this._parent.onEnterFrame;
                fullscreenMode = false;
                Stage["displayState"] = "normal";
                this._parent.icon_mc.gotoAndStop(1);
                objectsNormal();
        }
};
//
// LOAD VIDEO STREAM
//
// Reset video and controls
resetVideo = function () {
        durationDisplay = "0:00";
        controls_mc.progress_mc.buffer_mc._xscale = 0;
        controls_mc.progress_mc.played_mc._xscale = 0;
        videoEnd = false;
        doPlay();
};
resetVideo();
// Video stream
var nc:NetConnection = new NetConnection(this);
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.setBufferTime(defaultBuffer);
// Attach video stream
video_holder.videoClip.attachVideo(ns);
// Attach audio stream
video_holder.attachAudio(ns);
video_holder.videoClip.smoothing = true;
loadVideo = function () {
        resetVideo();
        ns.play(toLoad);
        ns.onMetaData = function(obj) {
                duration = obj["duration"];
                var minutes2:Number = Math.round(duration/60);
                var seconds2 = Math.round(duration%60);
                if (seconds2<10) {
                        seconds2 = "0"+seconds2;
                }
                durationDisplay = minutes2+":"+seconds2;
        };
};
//
// THUMB PRESS (LOADS VIDEO)
//
_global.thumbPress = function(obj) {
        toLoad = xmlNode.childNodes[galleryID].childNodes[obj.ID].attributes.VideoClip;
        videoTitle.text = xmlNode.childNodes[galleryID].childNodes[obj.ID].attributes.Title;
        galleryTitle.text = xmlNode.childNodes[galleryID].attributes.Name;
        loadVideo();
};

Ребята помогите убрать автоплай? Заранее спасибо.

ilikali 26.01.2011 01:38

Код AS1/AS2:

//
// SOUND CONTROLS
//
controls_mc.sound_time_mc.bttnSound.mc_soundLevel._visible = false;
controls_mc.sound_time_mc.bttnSound.bttn.onRollOver = function() {
        this._parent.mc_soundLevel._visible = true;
};
controls_mc.sound_time_mc.bttnSound.bttn.onRollOut = controls_mc.sound_time_mc.bttnSound.bttn.onDragOut=function () {
        if (!this._parent.mc_soundLevel.hitTest(_xmouse, _ymouse, true)) {
                this._parent.mc_soundLevel._visible = false;
        }
};
controls_mc.sound_time_mc.bttnSound.mc_soundLevel.onRollOut = function() {
        this._visible = false;
};
// Adjust volume on slider press
var video_sound:Sound = new Sound(video_holder);
video_sound.setVolume(defaultVolume);
controls_mc.sound_time_mc.bttnSound.mc_soundLevel.mc_bar._yscale = defaultVolume;
controls_mc.sound_time_mc.bttnSound.mc_soundLevel.onPress = function() {
        controls_mc.sound_time_mc.bttnSound.mc_soundLevel.onEnterFrame = function() {
                if (this._ymouse<0) {
                        volumeTo = 0;
                } else if (this._ymouse>this.bar._height) {
                        volumeTo = 100;
                } else {
                        volumeTo = (this._ymouse/this.bar._height)*100;
                }
                this.mc_bar._yscale = 100-volumeTo;
                video_sound.setVolume(100-volumeTo);
        };
};
// Adjust volume on slider release
controls_mc.sound_time_mc.bttnSound.mc_soundLevel.onRelease = controls_mc.sound_time_mc.bttnSound.mc_soundLevel.onReleaseOutside=function () {
        delete controls_mc.sound_time_mc.bttnSound.mc_soundLevel.onEnterFrame;
        this._visible = false;
};
//
// PLAY / PAUSE CONTROLS
//
// Button functions
doPlay = function () {
        ns.pause(false);
        controls_mc.bttnPlay.icon_mc.gotoAndStop(1);
};
doPause = function () {
        ns.pause(true);
        controls_mc.bttnPlay.icon_mc.gotoAndStop(2);
};
doRestart = function () {
        ns.seek(0);
        controls_mc.bttnPlay.icon_mc.gotoAndStop(1);
        ns.pause(false);
};
// Play button
controls_mc.bttnPlay.bttn.onPress = function() {
        if (controls_mc.bttnPlay.icon_mc._currentframe == 1) {
                doPause();
        } else {
                if (ns.time>=duration && duration != undefined) {
                        doRestart();
                } else {
                        doPlay();
                }
        }
};
// Rewind button
controls_mc.bttnRewind.bttn.onPress = function() {
        doRestart();
};
//
// PROGRESS BAR CONTROLS
//
// Adjust playhead on progress bar press
controls_mc.progress_mc.onPress = function() {
        controls_mc.progress_mc.onEnterFrame = function() {
                if ((this._xmouse*this._xscale)/100<0) {
                        this.percentage = 0;
                } else if ((this._xmouse*this._xscale)/100>this._width && this.buffer_mc._xscale == 100) {
                        this.percentage = 100;
                } else {
                        this.percentage = Math.round((this._xmouse*this._xscale)/100/this._width*100);
                }
                ns.pause(true);
                seekTime = this.percentage/100*duration;
                seekTime = Math.round(seekTime*100)/100;
                ns.seek(seekTime);
        };
};
// Adjust playhead on progress bar release
controls_mc.progress_mc.onRelease = controls_mc.progress_mc.onReleaseOutside=function () {
        if (this.percentage == 100) {
                doPause();
        } else {
                doPlay();
        }
        delete controls_mc.progress_mc.onEnterFrame;
};
onEnterFrame = function () {
        // Get video stream bytes loaded
        percentage = Math.round(ns.bytesLoaded/ns.bytesTotal*100);
        controls_mc.progress_mc.buffer_mc._xscale = percentage;
        // Get video time
        ns_seconds = ns.time;
        minutes = Math.floor(ns_seconds/60);
        seconds = Math.floor(ns_seconds%60);
        if (seconds<10) {
                seconds = "0"+seconds;
        }
        controls_mc.sound_time_mc.time_txt.text = minutes+":"+seconds+" / "+durationDisplay;
        // Progress bar position
        if (ns.time>=duration && duration != undefined) {
                controls_mc.progress_mc.played_mc._xscale = 100;
                if (videoEnd == false) {
                        controls_mc.bttnPlay.icon_mc.gotoAndStop(2);
                        videoEnd = true;
                }
        } else {
                controls_mc.progress_mc.played_mc._xscale = Math.round(ns.time*100/duration);
                videoEnd = false;
        }
};
//
// BUILD GALLERY
//
buildGallery = function () {
        // Reset scroll bar and menu item position
        menu_mc.bttn_mc._y = 0;
        menu_mc.scrollBttn._y = menu_mc.scrollBttn.originY;
        // Remove previously created menu items
        num = galleryTotal;
        for (j=0; j<num; j++) {
                menu_mc.bttn_mc["bttn"+j].removeMovieClip();
        }
        // Get number of items in gallery
        galleryTotal = xmlNode.childNodes[galleryID].childNodes.length;
        for (i=0; i<galleryTotal; i++) {
                // Build array with XML data
                Thumb[i] = xmlNode.childNodes[galleryID].childNodes[i].attributes.Thumb;
                VideoClip[i] = xmlNode.childNodes[galleryID].childNodes[i].attributes.VideoClip;
                Title[i] = xmlNode.childNodes[galleryID].childNodes[i].attributes.Title;
                Copy[i] = xmlNode.childNodes[galleryID].childNodes[i].attributes.Copy;
                // Build meny items
                menu_mc.bttn_mc.bttn.duplicateMovieClip("bttn"+i, i);
                menu_mc.bttn_mc["bttn"+i].ID = i;
                menu_mc.bttn_mc["bttn"+i]._y = menu_mc.bttn_mc.bttn._height*i;
                menu_mc.bttn_mc["bttn"+i].holder_mc.holder.loadMovie(Thumb[i]);
                menu_mc.bttn_mc["bttn"+i].title_txt.text = Title[i];
                menu_mc.bttn_mc["bttn"+i].copy_txt.text = Copy[i];
        }
        // Load first item in current gallery
        select_mc.selectShow.txt.text = Name[galleryID];
        toLoad = xmlNode.childNodes[galleryID].childNodes[0].attributes.VideoClip;
        videoTitle.text = xmlNode.childNodes[galleryID].childNodes[0].attributes.Title;
        galleryTitle.text = xmlNode.childNodes[galleryID].attributes.Name;
        loadVideo();
};
//
// LOAD XML
//
loadXML = function (loaded) {
        if (loaded) {
                xmlNode = this.firstChild;
                total = xmlNode.childNodes.length;
                Name = [];
                Thumb = [];
                VideoClip = [];
                Title = [];
                Copy = [];
                for (n=0; n<total; n++) {
                        // Get gallery name
                        Name[n] = xmlNode.childNodes[n].attributes.Name;
                        // Build gallery select menu
                        select_mc.selectBttn_mc.selectBttn.duplicateMovieClip("selectBttn"+n, n);
                        select_mc.selectBttn_mc["selectBttn"+n]._y = -select_mc.selectBttn_mc.selectBttn._height-(select_mc.selectBttn_mc.selectBttn._height)*n;
                        select_mc.selectBttn_mc["selectBttn"+n].txt_mc.txt.text = Name[n];
                        select_mc.selectBttn_mc["selectBttn"+n].ID = n;
                        select_mc.selectBttn_mc.selectBttn._visible = false;
                }
                buildGallery();
        } else {
                trace("Error loading XML");
        }
};
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("http://fcabsheron.az/content.xml");
xmlData.load("http://absheronfc.az/content.xml");
xmlData.load("http://absheronfc.com/content.xml");
xmlData.load("http://fcabsheron.com//content.xml");
stop();


rainbowrussia 26.01.2011 03:57

Попробуйте закоментировать
Код AS1/AS2:

loadVideo();

из второго "куска" или
Код AS1/AS2:

ns.play(toLoad);

.

olexandr 27.01.2011 06:29

сразу после начала загрузки, надо ставить на паузу
насколько я помню в нетСтрим нет функции лоад, поэтому после метода плей, сразу вызываем паузу

rainbowrussia 27.01.2011 14:25

Цитата:

Сообщение от olexandr (Сообщение 968203)
поэтому после метода плей, сразу вызываем паузу

Тогда трафик пойдет, а видео будет стоять на паузе. По делу надо грузить превью и не запускать нетстрим.

olexandr 27.01.2011 15:02

Цитата:

Сообщение от rainbowrussia (Сообщение 968279)
Тогда трафик пойдет, а видео будет стоять на паузе. По делу надо грузить превью и не запускать нетстрим.

Мы говорим о разных задачах. Вы говорите о чем-то вроде "автозагрузки", а я об "автопроигрывании".

ilikali 29.01.2011 14:56

Цитата:

Тогда трафик пойдет, а видео будет стоять на паузе. По делу надо грузить превью и не запускать нетстрим.
Это конечно же очень хорошо но навряд ли у меня получиться. Пробовал коментить но тогда видео вообще не грузиться.

Добавлено через 26 часов 41 минуту
Цитата:

Сообщение от rainbowrussia (Сообщение 968279)
Тогда трафик пойдет, а видео будет стоять на паузе. По делу надо грузить превью и не запускать нетстрим.

Можно ли сделать это? Был бы очень признателен если помогли?Превью можно и не показывать просто чтобы отображался значок плейа и виде не грузилось сразу.


Часовой пояс GMT +4, время: 20:16.

Copyright © 1999-2008 Flasher.ru. All rights reserved.
Работает на vBulletin®. Copyright ©2000 - 2024, Jelsoft Enterprises Ltd. Перевод: zCarot
Администрация сайта не несёт ответственности за любую предоставленную посетителями информацию. Подробнее см. Правила.